tags:

views:

22

answers:

1

Hi all,

I'm installing a network printers using vbscript and I want to show a friendly error if the queue doesn't exist or the printer server is unavailable, can I do this with VBScript? My code is below.

Dim net
Set net = CreateObject("WScript.Network") 
net.AddWindowsPrinterConnection "\\printsrv\HPLaser23"
net.SetDefaultPrinter "\\printsrv\HPLaser23"

Many thanks for the help

Steven

+1  A: 

Add the line:

On Error Resume Next ' the script will "ignore" any errors 

Before your code

and then do an:

if  Err.Number <> 0  then 
     ' report error in some way
end if
On Error GoTo 0 ' this will reset the error handling to normal

After your code

It's normally best to try to keep the number of lines of code between the On Error Resume Next and the On Error GoTo 0 to as few as possible, since it's seldom good to ignore errors.

ho1
Many thanks, worked perfectly.
Steve Wood