Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

del printers (never scripted before =) )

Status
Not open for further replies.

tech888

MIS
Sep 3, 2003
26
CA
I'm trying to get a script to delete all printers from a certain printer server (cal1) and add the printers I want with the default setting. however on some machines only one eng5si printer might exist. when i run the script it gives me an error that one eng5si connections doesn't exit, this is usually the first occurence (Thus is doesn't delete all the eng5si printers currently installed on the computer) Can any tell me how to write an if statement or some line that will bypass non existing printer connections and delete the rest of the eng5si on cal1.



this is the code
--------------------------------------------------------


Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\cal1\Eng5si1"
objNetwork.RemovePrinterConnection "\\cal1\Eng5si2"
objNetwork.RemovePrinterConnection "\\cal1\Eng5si3"

objNetwork.AddWindowsPrinterConnection "\\voyager\adminhp"
objNetwork.AddWindowsPrinterConnection "\\voyager\cgyadmin"
objNetwork.AddWindowsPrinterConnection "\\voyager\cgyadminDBS"

objNetwork.SetDefaultPrinter("\\voyager\adminhp")
 
Hi,
in your case, and because you want to "clean" your server, I suggest a "On Error Resume Next" statement at the beginning of your script.
That is, when a printer does not exists, the error doesn't stop the script.
Thats all. ;-)
 
I'm trying to do the same thing, plz help! By no means am I a coder. ;)

Is there special syntax for 'on eror resume next'?
 
that's exactly it.

the line is .........

On Error Resume Next

Rem : if an error occurs where there is no printer connection to REMOVE, the next line of code is execute
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top