如何在创建链接服务时处理错误

与大多数脚本一样,需要编写函数来处理任何错误。 此错误处理程序会扫描 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