Search code examples
windowsvbscriptwmiwindows-7-x64wmi-query

Err 80041017 when querying WMI on identical computers. (Win32_PerfFormattedData_PerfOS_Memory)


Why am I getting an error:

Code: 80041017
Source: (null)

on this line:

For Each oItem In colItems

in this VBScript:

strComputer = "."

Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
           & strComputer & "\root\cimv2")
Set cItems = oWMI.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Memory")
'wsh.echo cItems.Count

Display "Win32_PerfFormattedData_PerfOS_Memory", FillCol(cItems)

function FillCol(colItems)
  Dim oItem, oProp, s

  For Each oItem In colItems
    For Each oProp In oItem.Properties_
      s =  s & oProp.Name & vbcrlf
      's =  s & oProp.Name & vbtab & oProp.Value & vbcrlf
    Next 'oProp
    Exit For
  Next 'oItem

  FillCol = s
End Function 'FillCol

Sub Display(sTitle, s)
  'Display results in a scrollable window
  height = 600 : width = 800
  Set oIE = CreateObject("InternetExplorer.Application")
  With oIE
    .RegisterAsDropTarget = False
    .Toolbar = False : menubar = False : statusbar = False
    .Width = Width : .Height = Height
    .Navigate "about:blank"
    Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
    With .Document
      .Open
      .Write  "<xmp>" & s & "</xmp>"
      .Close
      .Title = sTitle
    End With
    .Visible = True
  End With 'oIE
End Sub

Taken directly from this link, except I changed:

Win32_PrinterConfiguration

To:

Win32_PerfFormattedData_PerfOS_Memory

On only one of two 64bit workstations with identical OS (Windows 7, both with current updates) and identical hardware specs. The computers are nearly identical and only one produces an error.

I have tried this fix to repair a corrupted WMI database:

But when I use:

Win32_PrinterConfiguration

instead of:

Win32_PerfFormattedData_PerfOS_Memory

I don't get an error.

What is going on? What do I need to do to get that script to work on the workstation that causes the error?

EDIT1: I am pretty sure the error is literally caused by a null return value. If so, why is there a null value for RAM? That just should be. Right?

EDIT2: Please comment regarding things to try or guesses.

EDIT3: The WMI diagnostic tool (https://www.microsoft.com/en-us/download/details.aspx?id=7684) says this:

28944 14:15:48 (1) !! ERROR: WMI GET operation errors reported: ........................................................................... 118 ERROR(S)! 28945 14:15:48 (0) ** - Root/CIMV2, Win32_PerfFormattedData_Counters_HTTPServiceRequestQueues, 0x0 - . 28946 14:15:48 (0) ** MOF Registration: 'WMI information not available (This could be the case for an external application or a third party WMI provider)' 28947 14:15:48 (0) ** - Root/CIMV2, Win32_PerfRawData_Counters_HTTPServiceRequestQueues, 0x0 - . 28948 14:15:48 (0) ** MOF Registration: 'WMI information not available (This could be the case for an external application or a third party WMI provider)' 28949 14:15:48 (0) ** - Root/CIMV2, Win32_PerfFormattedData_Counters_HTTPServiceUrlGroups, 0x0 - . 28950 14:15:48 (0) ** MOF Registration: 'WMI information not available (This could be the case for an external application or a third party WMI provider)' 28951 14:15:48 (0) ** - Root/CIMV2, Win32_PerfRawData_Counters_HTTPServiceUrlGroups, 0x0 - . 28952 14:15:48 (0) ** MOF Registration: 'WMI information not available (This could be the case for an external application or a third party WMI provider)'

...etc...

29069 14:15:48 (0) ** - Root/CIMV2, Win32_PerfFormattedData_PerfOS_Memory, 0x0 - . 29070 14:15:48 (0) ** MOF Registration: 'WMI information not available (This could be the case for an external application or a third party WMI provider)'

...etc...

Not sure what to do about those yet though.

EDIT4: looking at this fix:

Hi,

Please try the following troubleshooting suggestions to check the result:

Regsvr32 %SystemRoot%\System32\wbem\wmidcprv.dll

cd /d %windir%\system32\wbem

for %i in (*.dll) do RegSvr32 -s %i

for %i in (*.exe) do %i /RegServer

The Windows Management Instrumentation Tester window may appear, this is normal and we can go ahead to close it.

If it does not work, I also suggest you run the following commands to repair WMI namespace:

net stop winmgmt

wmic /NAMESPACE:\root path "__namespace.name='wmi'" delete

mofcomp %windir%\system32\wbem\wmi.mof

net start winmgmt

After that, please restart the computer to check the result. If the issue persists, please also try the following steps:

  1. Click the Start Button, All Programs, Accessories

  2. Right click "Command Prompt" and choose "Run as administrator", accept the UAC prompt.

  3. In the command prompt, type the following command and press Enter. Please type one command each time.

winmgmt /verifyrepository

winmgmt /salvagerepository

Regards,

Arthur Li

from: https://social.technet.microsoft.com/Forums/windows/en-US/df00b2e4-3bab-4b46-ad5a-95e82617a039/wmi-errors?forum=winserverNIS


Solution

  • reload the performance counters:

    cd %windir%\system32\
    lodctr /R
    cd %windir%\sysWOW64\
    lodctr /R
    

    found here: https://support.solarwinds.com/Success_Center/Server_Application_Monitor_(SAM)/Performance_counters_are_not_working_or_missing_in_PerfMon

    Note that the solution above was the last thing that I did that "solved" the issue; however, I did a lot of stuff from this link first: https://kb.paessler.com/en/topic/3713-i-have-tried-a-lot-of-things-to-fix-my-wmi-what-else-can-i-try-to-avoid-reinstalling-windows?utm_source=google&utm_medium=cpc&utm_campaign=USA_EN_DSA_KB_Pages&utm_adgroup=USA_EN_DSA_KB&utm_adnum=dsa_en_04&utm_campaignid=657889421&utm_adgroupid=34407076718&utm_targetid=dsa-256625615450&utm_customerid=779-315-3659&utm_location=9028770&gclid=EAIaIQobChMI_8zX88KP2QIVVQOGCh2S-gIMEAAYASAAEgIZtvD_BwE

    Not sure if the combination of things I did solved it or the 4 commands I put as my answer solved it. All I know is that it is working now!