共用方式為


How to Handle Configuration Manager Asynchronous 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

In Microsoft System Center Configuration Manager 2007, when an error occurs in an asynchronous call, the error object is passed as the second parameter to the OnCompleted method. Inside your OnCompleted implementation, you check the error object the same as you would for a synchronous call.

You determine if there is an error by checking the HResult parameter of the OnCompleted method.

Example

This VBScript sample displays error information if there is a error during an asynchronous operation. To use this code, replace the sink_OnCompleted method in How to Perform an Asynchronous Configuration Manager Query by Using WMI. To test, change the query to an invalid query such as Select * From ?????.

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

Sub sink_OnCompleted(HResult, oErr, oCtx)
    WScript.Echo "All collections returned"
 
    if HResult <> 0 Then 
    ' Determine the type of error.
        If oErr.Path_.Class = "__ExtendedStatus" Then
            WScript.Echo "WMI Error: "& oErr.Description            
        ElseIf ExtendedStatus.Path_.Class = "SMS_ExtendedStatus" Then
            WScript.Echo "Provider Error: "& oErr.Description
            WScript.Echo "Code: " & oErr.ErrorCode
        End If
    End If    
    bdone = true
End sub

Security

Using script to pass the user name and password is a security risk and should be avoided where possible.

See Also

Concepts

Configuration Manager Errors
Configuration Manager Objects Overview
How to Use Configuration Manager Objects with WMI
How to Perform an Asynchronous Configuration Manager Query by Using WMI
How to Handle Configuration Manager Synchronous Errors by Using WMI

Other Resources

WMI SDK