次の方法で共有


WMI を使用してConfiguration Manager同期エラーを処理する方法

Configuration Managerでは、エラーが発生したときにオブジェクトをSWbemLastError検査することで、同期エラーを処理します。 error オブジェクト Number プロパティが 0 以外の場合にエラーが発生しました。

注:

VBScript では、エラーが発生した場合にスクリプトの実行を再開することを宣言する必要があります。 それ以外の場合、エラー条件が発生するとスクリプトは終了します。 これを行うには、スクリプトで 宣言を On Error Resume Next 使用します。

次の VBScript の例では、オブジェクトから入手できる最新のエラー情報が SWbemLastError 表示されます。 無効なSMS_Package パッケージを取得してテストする次のコードを使用できます。

サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。


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

関連項目

エラーについて
WMI SDK