Share via


About the issue for the latest MP update(6.0.6000.3): “Failed to read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class.”

Update: Microsoft has published a Windows hotfix to resolve this issue~

Please refer the link https://support.microsoft.com/kb/2692929 for more details: "0x80041001" error when the Win32_Environment WMI class is
queried by multiple requestors in Windows 7 or in Windows Server 2008 R2

Issue Discription:

Recently, some of customers reported that they imported the new SCCM Monitoring Pack and encountered several script errors with the error message “Failed to read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class”. Peoples on the System Center Central forum(https://www.systemcentercentral.com/Forums/tabid/60/indexId/89622/vsdCurPage/1/Default.aspx?tag=Forums+Operations_Manager) also had long discussion about this but still no workaround to resolve it.

 

Repro: <Executing multiple scheduled task(~4) to execute following script>

Environment: Windows Server 2008 R2

On Error Resume Next

Dim sCimv2namespace, sProcArchQuery, oProcArchObjectSet, oProcArchObject, sProcArch

sCimv2namespace = "winmgmts:\\.\root\cimv2"

sProcArchQuery = "Select * From Win32_Environment Where Name = ""Processor_Architecture"""

Set oProcArchObjectSet = WMIExecQuery (sCimv2namespace, sProcArchQuery)

Set oProcArchObject = oProcArchObjectSet.Item("Win32_Environment.Name=""PROCESSOR_ARCHITECTURE"",UserName=""<SYSTEM>""")

sProcArch = oProcArchObject.VariableValue

On Error GoTo 0

Select Case sProcArch

  Case "AMD64"

    REG_PATH_SMS = "SOFTWARE\Wow6432Node\Microsoft\SMS"

  Case "x86"

    REG_PATH_SMS = "SOFTWARE\Microsoft\SMS"

  Case Else

     ScriptError "read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class."

End Select

 

Investigation:

Actually, this error is caused by a Windows WMI bug, when there are multiple scheduled tasks to executing the script and it will fail after some times with 0x80041001 /WBEM_E_FAILED.

 

Workaround:

Option#1:

Modify the script to check the registry instead of WMI.

Sample:  Modify the System Center Operations Manager 2007\Health Service State\Management
Pack\Microsoft.SystemCenter.ConfigurationManager.2007.{GUID}{GUID}.xml

-------------------------------- Disable/remove all of the WMI check script in the xml----------------------------

On Error Resume Next

Dim sCimv2namespace, sProcArchQuery, oProcArchObjectSet, oProcArchObject, sProcArch

sCimv2namespace = "winmgmts:\\.\root\cimv2"

sProcArchQuery = "Select * From Win32_Environment Where Name = ""Processor_Architecture"""

....

....

ScriptError "read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class."

End Select

-------------------------------- Use following registry check script instead ----------------------------

Please note, the Sub Main of the script for ConfigMgr 2007 Monitor SMS Executive Crash Dumps would set the REG_KEY_IDENTIFICATION(not REG_PATH_SMS) after the processor architecture check.

If (CheckWow64RegistryKeyExists() = True) Then

  REG_PATH_SMS = "SOFTWARE\Wow6432Node\Microsoft\SMS"  ‘ or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION

Else

  REG_PATH_SMS = "SOFTWARE\Microsoft\SMS"  ‘ or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION

End If

------------------------------------------------------------------------------------------------------------------------------

 

Option#2:

Add code to retry the WMI Query when the query failed for the first time.

Sample: Modify
the System Center Operations Manager 2007\Health Service State\Management
Pack\Microsoft.SystemCenter.ConfigurationManager.2007.{GUID}{GUID}.xml

-------------------------------- Disable/remove all of the WMI check script in the xml----------------------------

On Error Resume Next

Dim sCimv2namespace, sProcArchQuery, oProcArchObjectSet, oProcArchObject, sProcArch

sCimv2namespace = "winmgmts:\\.\root\cimv2"

sProcArchQuery = "Select * From Win32_Environment Where Name = ""Processor_Architecture"""

....

....

ScriptError "read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class."

End Select

-------------------------------- Use following script
instead(would try to query the WMI 5 times with 5 seconds period) ----------------------------

Please note, the Sub Main of the script for ConfigMgr 2007 Monitor SMS Executive Crash Dumps would set the REG_KEY_IDENTIFICATION (not REG_PATH_SMS) after the processor architecture check.

 

Dim sCimv2namespace, sProcArchQuery, oProcArchObjectSet, oProcArchObject, sProcArch, StartTimeA, EndTimeB, TimeOutC, RetryResult, RetryCount, RetryErrMessage

sCimv2namespace = "winmgmts:\\.\root\cimv2"

sProcArchQuery = "Select * From Win32_Environment Where Name = ""Processor_Architecture"""

RetrunResult = false

RetryCount = 5 'will retry 5 times

TimeOutC = 5 'wait 5 sec per time

 

Do While RetryCount > 0

  On Error Resume Next

  Set oProcArchObjectSet = WMIExecQuery (sCimv2namespace, sProcArchQuery)

  Set oProcArchObject = oProcArchObjectSet.Item("Win32_Environment.Name=""PROCESSOR_ARCHITECTURE"",UserName=""<SYSTEM>""")

  sProcArch = oProcArchObject.VariableValue

  If Err.Number <> 0 Then

    RetryCount = RetryCount – 1

    ‘if encountered runtime error, then collect the error message into RetryErrMessage.

    RetryErrMessage = RetryErrMessage + "Try#" & 5 - RetryCount & ":Runtime Error(" & CStr(Err.Number) & ") - " & Err.Description & ";"

  Else

    Select Case sProcArch

        Case "AMD64"

                REG_PATH_SMS = "SOFTWARE\Wow6432Node\Microsoft\SMS" ‘or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION

                RetryResult = true

                Exit Do 

        Case "x86"

                REG_PATH_SMS = "SOFTWARE\Microsoft\SMS"  ‘or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION

                RetryResult = true

                Exit Do

        Case Else

                RetryCount = RetryCount – 1

                ‘if not a runtime error, then it should be an invalid value, so collect the invalid value into RetryErrMessage

                RetryErrMessage = RetryErrMessage + "Try#" & 5 - RetryCount & ":Invalid Value - '" & sProcArch & "', should be 'AMD64' or 'x86';"

   End Select

  End If

  ‘waiting...

  StartTimeA = Timer

  EndTimeB = 0

  Do While EndTimeB - StartTimeA <= TimeOutC

    EndTimeB = Timer

    If EndTimeB < StartTimeA Then

      StartTimeB = EndTimeA

    End If

  Loop

  On Error GoTo 0

Loop

 

‘if retry to get the value successfully, then it would not report the pervious error.

If RetryResult = false Then

ScriptError "read %PROCESSOR_ARCHITECTURE environment variable from Win32_Environment WMI class. Script tried to query the WMI 5 times but all failed... [Error Detail]: " & RetryErrMessage

End If

Comments

  • Anonymous
    March 04, 2012
    The comment has been removed
  • Anonymous
    March 04, 2012
    ah, maybe i should've specified that im using Notepad ++ to view the file. I just deleted the part that prompts the WMI and added the: If (CheckWow64RegistryKeyExists() = True) Then  REG_PATH_SMS = "SOFTWAREWow6432NodeMicrosoftSMS"  ‘ or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION Else  REG_PATH_SMS = "SOFTWAREMicrosoftSMS"  ‘ or REG_KEY_IDENTIFICATION = REG_KEY_WOW64_IDENTIFICATION End If in the same place.