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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove network printers... if they exist. 3

Status
Not open for further replies.

ModularIT

IS-IT--Management
May 10, 2001
39
0
0
AU
Hello

I'm putting together a very simple script to add some new network printers and remove old ones. I want to apply the same script to all users but the trouble is than not all of them have the same old printers for removal.

I'm using the line 'WshNetwork.RemovePrinterConnection "\\server\printer"'but obviously the script stops and generates an error if the specified printer doesn't exist on the computer.

Is there some code I can use to say if this printer exists delete it, if not continue to the next line?

Thanks
Nick
 
Have a look at Mark's FAQ logon script. It has a very nice routine to remove all network connected printers as well as several other very useful examples.

faq329-5798

Thanks

John Fuhrman
Titan Global Services
 
Not only that, but if you know that you will get an error then just put an On Error Resume Next and On Error Goto 0 in the For...Each Loop

i.e.

For Each xxxx in XXXX
On Error Resume Next
'remove printer cmd
On Error Goto 0
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks for the props John. :)

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top