i'm writing a script that will set a network printer as a global printer assigned to a computer so when a new user logs in they won't have to manually add the printer it will already be there. I'm using the command rundll32 printui PrintUIEntry. So we'll have techs going around to each computer (being admins on the computer) and they'll run this script. A pop up box will come up and they'll type in the printer name and it ok and it runs the rundll32 command. We have 2 printer servers "vps01" and "vps02" so the command will run twice looking for the printer. I'm having a problem with error handling. I'm not sure where to start. I tried setting up error handling but i know it's wrong. The way i have it the command runs but if i put in a invalid printer name it still says the printer is added. Any help is much appreciated.
Dim objNet, strPrinter
Set objNet = CreateObject("Wscript.Network")
strPrinter = InputBox("Please enter the name of the Printer you'd like to add", "Add Printer", "eg. printer name")
Set objShell = CreateObject("WScript.Shell")
arrServers = Array("vps01","vps02")
For Each strServer In arrServers
strCommand = "cmd /c rundll32 printui.dll,PrintUIEntry /ga /n\\" & strServer & "\" & strPrinter
objShell.Run strCommand, 1, True
next
If err.number = 0 Then
Wscript.Echo strPrinter & " added!"
Else
Wscript.Echo "Uh oh - there seems to be a problem! Error Code : " & err.number & " Error Description: " & err.description
End If