WMI: Rebuilding the WMI Repository

WMI: Rebuilding the WMI Repository

  • Comments 24
  • Likes

REBUILDING THE WMI REPOSITORY


Scenario Windows Management Instrumentation fails due to repository corruption or the repository is too large

The WMI Repository "%windir%System32\Wbem\Repository" is the database that stores meta-information and definitions for WMI classes; in some cases the repository also stores static class data as well. If the Repository becomes corrupted, then the WMI service will not be able to function correctly.

If you suspect WMI or repository corruption, rebuilding repository is the last thing you should do. Deleting and rebuilding the repository can cause damage to the system or to installed applications. Other steps should be taken first to eliminate other possibilities or to confirm we have repository corruption. An extremely large Repository also creates problems and can sometimes be interpreted as a corrupt repository, which is not always the case. If issues are due to a large repository, rebuilding the repository is currently the only method available to reduce the repository size.

It's a good idea to alwasy capture a WMIDiag report for any WMI related issues:

If WMI is corrupted, you can receive various errors depending on what activity was being accomplished at the time.

Below are a few scenarios/errors that indicate repository corruption:

  • Unable to connect to root\default or root\cimv2 namespaces thru wbemtest. Fails returning error code 0x80041002 pointing to WBEM_E_NOT_FOUND
  • When we open Computer Management and Right Click on Computer Management(Local) and select Properties, you get the following error: "WMI: Not Found" or it hangs trying connect
  • 0x80041010 WBEM_E_INVALID_CLASS
  • Trying to use wbemtest, it hangs

Actions to try

First try the following actions to see if they resolve your issue:


    a. Re-register all of the dlls and recompile the .mofs in the wbem folder and re-registering WMI Service and Provider. You can use the following script by saving to txt file then renaming to .bat and running from command prompt with admin right and changing focus to following directory: C:\Windows\System32\Wbem.

@echo off
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s

    b. Reboot the machine and test WMI

Next, check the repository for consistencies:

For Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2, you can run winmgmt /verifyrepository from a command prompt.
For Older OS like Windows XP and Windows Server 2003 run: WmiDiag tool with the checkconsistency option. For example: WmiDiag checkconsistency

If repository is found to be inconsistent:

    a. For Vista and newer, run from elevated command prompt:

Winmgmt /salvagerepository

Note this command will take the content of the inconsistent repository and merge it into the rebuilt repository if it is readable

If the above doesn’t work, then run:

Winmgmt /resetrepository

Note this will reset repository to the initial state when the OS was first installed

For Windows XP and Windows Server 2003, there are no built in switches to rebuild the Repository, so you must do it manually.

Warning: Rebuilding the WMI repository has resulted in some 3rd party products not working until their setup is re-run & their MOF re-added back to the repository. 

If /salvagerepository or /resetrepository does not resolve the issue, then manually rebuild repository:

  1. Change startup type to Window Management Instrumentation (WMI) Service to disabled
  2. Stop the WMI Service; you may need to stop IP Helper Service first or other dependent services before it allows you to stop WMI Service
  3. Rename the repository folder:  C:\WINDOWS\system32\wbem\Repository to Repository.old
  4. Open a CMD Prompt with elevated privileges
  5. CD windows\system32\wbem
  6. for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
  7. Set the WMI Service type back to Automatic and start WMI Service
  8. cd /d c:\  ((go to the root of the c drive, this is important))
  9. for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s
  10. Reboot the server

Finally, install latest hotfixes for WMI as they can help prevent issue from recurring. If you continue to have recurring WMI repository corruption issues on same machine, please engage a Microsoft Support Engineer for further troubleshooting and assistance.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • try Winmgmt /resetrepository, have access denied.

    My logon id suppose have admin right.

  • Even i tried above step, still having issue with software inventry collection

  • Winmgmt /salvagerepository worked a treat!  Thanks!

  • Hi Team,

    I was going to fix the SCCM client issue. But notice the WMI is corrupted.

    Stopped the service. Renamedd the repository in Wbem folder to old. but now wmi option to restart,start and stop are disabled.

  • Team,

    We have pushed the SCCM patches for windows 2008r2,2003 servers. we checked and found no issues with the client health. We encountered no state data under it we saw that the status shows that no state data.

    I want to know what this signifies. Does it mean that client health is not OK or it means WMI is not working fine.  I have been expoloring but had found no answers to it.

    We did fix the client issues on the servers. But still they are not compliant.

  • @All: You should not rename the WMI Repository folder manually in Vista or higher.  To resolve WMI issues, first make sure you have the latest WMI hotfixes, then run the commands associated with "winmgmt.exe".

  • There are a couple typos in that batch script. Here is the corrected version:

    @echo off

    sc config winmgmt start= disabled

    net stop winmgmt /y

    %systemdrive%

    cd %windir%\system32\wbem

    for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s

    wmiprvse /regserver

    winmgmt /regserver

    sc config winmgmt start= auto

    net start winmgmt

    for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s

  • @Ryan Steele:  Thanks for the heads up.  I have made the corrections.

  • I think it is important to clarify and remember that when running in commandline, use

    for /f %s ....

    while in a batch file, use

    for /f %%s ...

  • What is ie script error # 53 and how can I stop it from popping up?

  • thank you so much. i have managed to fix my issue using this post.

  • i am trying to connect to root/onguard, its giving me hex error (80041002), is it a case of WMI corruption. Though i am able to connect root/cimv2 and parse the result even remotely.

  • 80041002 is WBEM_E_NOT_FOUND which means WMI cannot find root/onguard.  You need to register the MOF file that will add this namespace in to the WMI repository for that product.

  • For me, repair of WMI repository via this script was incomplete, Server Manager in Server 2012 show errors like here social.technet.microsoft.com/.../windows-server-2012-server-manager-error-online-data-retrieval-failures-occured

    I manage to fix them by adding to script registration of 32-bit components as well as 64-bit (based on social.technet.microsoft.com/.../health-service-warnings )

    sc config winmgmt start= disabled

    net stop winmgmt /y

    %systemdrive%

    cd %windir%\system32\wbem

    for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s

    for /f %%s in ('dir /b *.exe') do regsvr32 /s %%s

    cd %windir%\sysWOW64\wbem

    for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s

    for /f %%s in ('dir /b *.exe') do regsvr32 /s %%s

    cd %windir%\system32\wbem

    wmiprvse /regserver

    winmgmt /regserver

    sc config winmgmt start= auto

    net start winmgmt

    cd %windir%\system32\wbem

    for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s

    cd %windir%\sysWOW64\wbem

    for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s

    pause

  • @bazanovv:  Did "Winmgmt /resetrepository" not work?