Deleting and adding network printers

Status
Not open for further replies.

Osiris

Golden Master
Messages
36,817
Location
Kentucky
Here is what I'm trying to accomplish.

I am incorporating this into my login.bat file which maps user network drives and checks SAV status. When the users mapped drives are missing, they simply run the batch file and it remaps their drives. Now since I add/remove, rename, etc printers often, I need a batch file to remove the current network printers and then add the new network printers. Now with what I have, it works great as long as the user have the printers listed below, but if they don't, the user will be promted with 14 error messages and they need to press ok each time. This error message appears from the first section on the batch file with the switch /gd which deletes a printer, /ga adds a printer. Now I need to add an IF statement meaning, if this network printer is present, dont delete it. IF this network printer is not present, skip it and go to the next printer to delete. When the batch file completes the first delete section, stops and restarts the local print spooler it then goes to the add printers section.

So this batch file needs to run with no user interaction wether or not the printer is there or not since this will be tied in together with the map drives batch files.

So where would I add the IF statements or IF EXISTS statements?

Here is what I have so far which works perfect on computers that have all their printers, even if they have no connection to the server. But it dont work perfect on computers that have no printers installed, an example would be a new user. All he would have to do is run the batch file and he is done. This would cut down on the number of calls I get if I can get this to work perfect.



rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /gd /n \\hebfps001\HEBHP8150-001"

net stop spooler
net start spooler




rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8150-001"

net stop spooler
net start spooler
 
Warez, have you ever attempted this on a remote level? Basically, having the batch files under your control using the remote node name switch? Had to do some searching because it's been a while and I forgot the remote switch... hehehehe.... but it's /c[name]. So, /c\\ComputerName ... and i'm sure it's put into the script prior to the /gd or /ga. Something else to try is the switch not to display errors when installing and removing printers. Not sure if it works with /gd or not but try the /q switch.

Mind you, it's been a terribly long time since i've used a PrintUIEntry script :) hehehe.

(You've probably already tried these :( but i thought that i'd throw them out there anyway :) )
 
Thanks, the /q switch worked, here is what I have now:

rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8150-001"
net stop spooler
net start spooler

rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /ga /n \\hebfps001\HEBHP8150-001"
net stop spooler
net start spooler



A problem I have now is I can't delete some printers. "Printer not found on server, unable to connect" is the status, those are the printers I can delete manually but not using the command. I have stopped the print spooler, disconnected from the network, rebooted, ran the remove command, and I still can't delete these 4 printers. When I run the add printers, it add all the printers, even the printers I can't remove. Is there a stronger command/switch to remove these printers no matter what their status?
 
I figured out why I couldn't remove those printers. I had changed the name of the printer on the server and the share name wasn't in the remove section of the batch file, so I added it and they were removed, duh. But I still have 2 printers I can't delete and I'm not sure why..... :confused:
 
Turns out it was my wonderful typos. Now all printers delete without error and add perfectly with no unable to connect error messages, etc. Now I'm going to add this to our login.bat to solve a major problem I have. Thanks!
 
Here is the completed list. The delete section has more printers because I changed the printer names so I had to add the before name and after name to reflect the changes. Once everyone has ran this batch file for a week or so, I'll edit it and so there will be the same number or printers on delete and add. :rolleyes:


----------------------------------------------------------------------------

rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP8150-001"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBXerox-002"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBxerox002"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHPDESKJET-001"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBDESKJET-001"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-003_Dframe"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP1320-001"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBDESKJET-001"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBHP4050-003_Assembly"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBxerox002"
rundll32 printui.dll,PrintUIEntry /gd /q /n \\hebfps001\HEBOfficeXerox-001"

net stop spooler
net start spooler

rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4000-001_Assembly_Rack"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4000-002_Receiving"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4000-003_Materials"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4050-001_QA_Lab"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4050-004_Assembly"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4600-001_Office_Color"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP8100-001_Pick_List"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP8100-002_UPS_Line"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP8150-001"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBXerox-002"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHPDESKJET-001"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP4050-003_Dframe"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBHP1320-001"
rundll32 printui.dll,PrintUIEntry /ga /q /n \\hebfps001\HEBOfficeXerox-001"

net stop spooler
net start spooler

---------------------------------------------------------------------------
 
The next thing I would like to add to this is to run this minimized. When our login.bat run after we log in, the cmd windows is minimized. I'm not sure if that's by nature or its the batch/script/kix file somewhere. I tried using start /min and start /min <name of the file> but when I launch the remove/add printers.bat, it executes another window and runs the bat file twice. The second one returns errors but is unaffected by the user and the printers still remove and add.
 
where are you placing the start /min ? Sounds like it needs to sync with itself. Try using the /wait switch with /min .

If you are running it totally quiet and nothing pops up that requires user intervention, then you could just run it completely invisible.

save this below into a file called "inviscmd.vbs"
Code:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

then run your add/remove script with the wscript.exe file (with the vbs running before it... like this:
Code:
wscript.exe "C:\PathOfTheinviscmdFileYouCreated\inviscmd.vbs" "C:\PathOfYourRemoveAddPrinterBatchFile\addremptr.bat"
 
Yea, I just tried calling your batch file using the
Code:
wscript.exe "C:\PathOfTheinviscmdFileYouCreated\inviscmd.vbs" "C:\PathOfYourRemoveAddPrinterBatchFile\addremptr.bat"

cmd.exe ran in the background for approx 10 seconds (enough time to delete each printer, stop and start the spooler and then add the printers, stop and restart the spooler.)

I wasn't sure if it actually worked totally invisible with the /gd and /ga switches. But, yea, it works fine.

So, instead of simply calling the printer batch file, call the vbs file prior to it with wscript.exe
 
That worked. But on second thought, maybe this wouldn't be a good idea. Users like to see that when they click on something, they want to see something happening so if they run it without them seeing it, they may keep clicking the file so maybe I will just keep it like it is. :D
 
Status
Not open for further replies.
Back
Top Bottom