Udostępnij za pośrednictwem


How to Handle Configuration Manager Synchronous Errors by Using WMI

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

You handle synchronous errors, in Microsoft System Center Configuration Manager 2007, by inspecting the SWbemLastError object when an error occurs. An error has occurred when the error object Number property is non-zero.

Note

In VBScript you should declare that you want to resume running the script if an error occurs. Otherwise, the script will end when an error condition occurs. To do this, use the On Error Resume Next declaration in your script.

Example

The following VBScript example displays the most recent error information that is available from the SWbemLastError object. You can use the following code, which tries to get an invalid SMS_Package package to test it. For more information about getting the connection parameter, see How to Connect to an SMS Provider in Configuration Manager by Using WMI.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub ExerciseError(connection)

    On Error Resume next

    Dim packages
    Dim package
    
    ' Run the query.
    Set package = connection.Get("SMS_Package.PackageID='UNKNOWN'")
    
    If Err.Number<>0 Then
        Call DisplayLastError
    End If
   
End Sub    
Sub DisplayLastError
    Dim ExtendedStatus
    
    ' Get the error object.
    Set ExtendedStatus = CreateObject("WbemScripting.SWBEMLastError")
     
    ' Determine the type of error.
    If ExtendedStatus.Path_.Class = "__ExtendedStatus" Then
        WScript.Echo "WMI Error: "& ExtendedStatus.Description            
    ElseIf ExtendedStatus.Path_.Class = "SMS_ExtendedStatus" Then
        WScript.Echo "Provider Error: "& ExtendedStatus.Description
        WScript.Echo "Code: " & ExtendedStatus.ErrorCode
    End If
End Sub

Security

See Also

Concepts

Configuration Manager Errors
Configuration Manager Objects Overview
How to Use Configuration Manager Objects with WMI
How to Connect to an SMS Provider in Configuration Manager by Using WMI

Other Resources

WMI SDK