Editar

Partilhar via


How to Handle Errors While Creating a Link Service

As with most scripts, you need to write functions to handle any errors. This error handler scans the Windows Management Instrumentation (WMI) error queue for any relevant error information and posts and displays the error to the user.

The following sample shows how to handle errors while you are creating a link service:

Syntax

  
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