The last two months, I was helping a client to get his network running smoothly again. One of the topics were strange errors within various applications and problems with machines that did not received any update from the central Windows Server Update Services.
To cut a long story short, this all was caused by the WMI (Windows Management Instrumentation) service not working correctly. One very often rolled out image was broken in that area so 70% of all computers had a broken WMI installation.
After some research, I created a WMI Fixer batch file that was able to fix the WMI installation of nearly all machines (>400), except three we were forced to reinstall.
I took the idea from a script of David H. Lipman from this forum post, added some checking logic and also added some code from the WMI Isn't Working page.
Enjoy!
@cls
echo off
Rem
Rem Original by David H. Lipman: http://www.pcreview.co.uk/forums/thread-1898592.php
Rem See also: http://www.microsoft.com/technet/scriptcenter/topics/help/wmi.mspx
Rem
SET WMIRoot=%windir%\system32\wbem
SET Rep_Bad=Repository_bad
echo WMI Fixer Batch v1.2
echo Copyright (C) 2008 Xteq Systems
echo http://www.xteq.com/
echo.
echo Setting TEMP as current directory
cd /d %TEMP%
if exist %WMIRoot% goto Stop_Services
echo WMI doesn't seem to be installed here! Starting WMICore.exe...
wmicore /s
echo Creating folder WBEM
mkdir %WMIROOT%
:Stop_Services
echo Trying to stop service...
net stop winmgmt /y
echo Using kill switch to make sure WMI has stopped...
winmgmt /kill
echo Switching to %WMIRoot%
cd /d %WMIRoot%
echo Checking if folder %Rep_Bad% exists and delete it if necessary
if exist %Rep_Bad% rd %Rep_Bad% /s /q
echo Moving current Repository to %Rep_Bad%..
rename Repository %Rep_Bad%
echo Registering all DLL files...
echo on
@for %%i in (*.dll) do RegSvr32 -s %%i
@echo off
echo Registering all EXE files...
for %%i in (*.exe) do call :FixSrv %%i
REM for %%i in (*.mof,*.mfl) do Mofcomp %%i
Rem not used
net start winmgmt
echo Done!
goto Ende
:FixSrv
if /I (%1) == (mofcomp.exe) goto SkipSrv
if /I (%1) == (wmic.exe) goto SkipSrv
if /I (%1) == (wbemcntl.exe) goto SkipSrv
if /I (%1) == (wbemtest.exe) goto SkipSrv
echo on
%1 /RegServer
@echo off
:SkipSrv
goto LongTail
:Ende
pause
exit 0
:LongTail
No comments:
Post a Comment