我正在使用vbscript安装网络打印机,如果队列不存在或打印机服务器不可用,我想显示一个友好的错误,我可以使用VBScript吗?我的代码如下.
Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\printsrv\HPLaser23"
net.SetDefaultPrinter "\\printsrv\HPLaser23"
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助
史蒂芬
添加行:
On Error Resume Next ' the script will "ignore" any errors
Run Code Online (Sandbox Code Playgroud)
在你的代码之前
然后做:
if Err.Number <> 0 then
' report error in some way
end if
On Error GoTo 0 ' this will reset the error handling to normal
Run Code Online (Sandbox Code Playgroud)
在你的代码之后
通常最好尝试将 和 之间的代码行数保持得On Error Resume Next尽可能On Error GoTo 0少,因为忽略错误很少有好处。