WMI error when viewing dependencies of services

After a restore from the backup of a server, I found myself fighting a WMI issue.
Whenever I tried to view the dependencies of a service through services.msc I got the error an WMI error. I immediately noticed that the Windows Management Instrumentation service was stopped and when trying to start it I got a cryptic error.

To make an afternoon of troubleshooting short, my solution was the following script:

@echo on
cd /d c:\temp
if not exist %windir%\system32\wbem goto TryInstall
cd /d %windir%\system32\wbem
net stop winmgmt
winmgmt /kill
if exist Rep_bak rd Rep_bak /s /q
rename Repository Rep_bak
for %%i in (*.dll) do regsvr32 -s %%i
for %%i in (*.mof,*.mfl) do Mofcomp %%i
net start winmgmt
goto end

:FixSrv
if /I (%1) == (wbemcntl.exe) goto End
if /I (%1) == (mofcomp.exe) goto End
%1 /RegServer

:TryInstall
if not exist wmicore.exe goto End
wmicore /s
net start winmgmt
:End

This script basically re-registers all *.dll, *.mof and *.mfl files related to the service Smile

10 comments

  1. Marvin_nance says:

    This worked like a charm!  Took me about an hour to find the script but it worked beautifully.

  2. Conundrum101 says:

    Great job!! thanks !

  3. Geelbaksteen says:

    Like a BOSSS!

  4. Anon says:

    FTW. Thanks for posting. BTW one small error in your script:
    Replace this line:
    for %%i in (*.mof,*.mfl) do Mofcomp %%1
    with this:
    for %%i in (*.mof,*.mfl) do Mofcomp %%i
    ^ The change is from number 1 to letter i

  5. Anon says:

    I also found this page helpful:
    http://smallvoid.com/article/winnt-wmi-config.html
    if the WMI repository is corrupt. Depending on what version of Windows,
    there are different ways to repair/rebuild/reset the WMI repository:

    Windows Vista/2008:

    winmgmt /verifyrepository

    winmgmt /salvagerepository

    Windows XP (Requires atleast SP2):

    rundll32 wbemupgd, UpgradeRepository

    Windows 2003 (Requires atleast SP1):

    rundll32 wbemupgd, RepairWMISetup

    Other versions (Note it will reset the ICS and ICF configuration):
    winmgmt /clearadapwinmgmt /killwinmgmt /unregserverwinmgmt /regserverwinmgmt /resyncperfnet stop winmgmtdel %windir%system32WbemRepository*.* /snet start winmgmt%windir%system32wbemwbemtest.exe

  6. Jeff Wouters says:

    HI Anon,
    Thanks for noticing, changed the code 🙂
    Jeff.

  7. Carol says:

    so is the idea to go into the command prompt area, run as administrator and past this script in?

  8. Jeff Wouters says:

    Hi Carol,
    Not exactly… Create a batch file with the code in it and execute it in elevated mode (run as admin).
    Jeff.

  9. Ben_13 says:

    Man, thank you so much for this. I was very close to reinstalling and this helped me out imensly.

  10. Jeff Wouters says:

    Hi Ben,
    You’re very welcome 🙂
    Jeff.

Leave a Reply

Your email address will not be published. Required fields are marked *