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.
Visual Basic Script | Copy Code |
---|---|
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 |
Visual Basic Script | Copy Code |
---|---|
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
Send comments about this topic to Microsoft.