Can I get vbscript to show a friendly error message?
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
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.
精彩评论