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
This worked like a charm! Took me about an hour to find the script but it worked beautifully.
Great job!! thanks !
Like a BOSSS!
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
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
HI Anon,
Thanks for noticing, changed the code 🙂
Jeff.
so is the idea to go into the command prompt area, run as administrator and past this script in?
Hi Carol,
Not exactly… Create a batch file with the code in it and execute it in elevated mode (run as admin).
Jeff.
Man, thank you so much for this. I was very close to reinstalling and this helped me out imensly.
Hi Ben,
You’re very welcome 🙂
Jeff.
It’s Working now!! Thanks much.