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

Help with this script

Status
Not open for further replies.

madison2008

IS-IT--Management
Oct 27, 2008
4
US
I am trying to delete a selected network printers for our users but in the real world, some user may only have 1 or of the 3 printers I needed to delete installed. For example if the user only has canon2 and canon3 installed, the script errors out because it does not detect canon1 and the script will terminate. I wanted it so it continues to deleted the other canons even if 1 or two of the 3 are missing. Here is the script. I appreciate your help.


Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.RemovePrinterConnection "\\sny-apps\canon1"
WshNetwork.RemovePrinterConnection "\\sny-apps\canon2"
WshNetwork.RemovePrinterConnection "\\sny-apps\canon3"
 
Thanks ettienne. Where do I insert that code? Below is still not working. Thanks again.



Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\sny-apps\canon1"
On Error Resume Next
WshNetwork.RemovePrinterConnection "\\sny-apps\canon2"
On Error Resume Next
WshNetwork.RemovePrinterConnection "\\sny-apps\canon3"

 
Nevermind I got it to work. Thank you ettienne.


Set WshNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
WshNetwork.RemovePrinterConnection "\\sny-apps\canon1"
On Error Resume Next
WshNetwork.RemovePrinterConnection "\\sny-apps\canon2"
On Error Resume Next
WshNetwork.RemovePrinterConnection "\\sny-apps\canon3"



 
You only need it once at the beginning, sorry I assumed you would know that.
 
Totally new to vbscripting, still reading on WSH and VBScripting Programming 2nd Edition for absolute beginner. Thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top