如何在建立連結服務時處理錯誤
如同大部分的腳本,您需要撰寫函式來處理任何錯誤。 此錯誤處理常式會掃描 Windows Management Instrumentation (WMI) 錯誤佇列中是否有任何相關的錯誤資訊和貼文,並向使用者顯示錯誤。
下列範例示範如何在您建立連結服務時處理錯誤:
語法
Sub PrintWMIErrorThenExit(strErrDesc, ErrNum)
On Error Resume Next
Dim objWMIError : Set objWMIError = CreateObject("WbemScripting.SwbemLastError")
wscript.echo TypeName(objWMIError)
If ( TypeName(objWMIError) = "Empty" ) Then
wscript.echo strErrDesc & " (HRESULT: " & Hex(ErrNum) & ")."
Else
wscript.echo "Extended error information:"
wscript.echo objWMIError.Description
Set objWMIError = nothing
End If
Exit sub
End Sub