If WMI applications/scripts error, or no longer function, you may have a corrupted WMI repository. I have scripted WMIRepository.bat to correct the corruption.

The syntax for using WMIRepository.bat is:


WMIRepository.bat contains:

                              @echo off                              setlocal ENABLEDELAYEDEXPANSION                              set key=HKLM\System\CurrentControlSet\Services                              set file="%TEMP%\WMIRepository_%RANDOM%.tmp"                              if exist %file% del /q %file%                              for /f "Tokens=*" %%a in ('reg query %key%^|find "HKEY_LOCAL_MACHINE"') do (                               set OK=N                               set svc="%%a"                               call :quiet !svc!>nul 2>&1                               if "!OK!" EQU "Y" call :depend !svc!                              )                              net stop winmgmt                              @ping -n 4>nul                              pushd %systemroot%\system32\wbem                              if exist Repository RD /S /Q Repository                              popd                              if not exist %file% goto swmi                              for /f "Tokens=*" %%a in ('type %file%') do (                               net start %%a                              )                              :swmi                              call :wmi>nul 2>&1                              if exist %file% del /q %file%                              endlocal                              goto :EOF                              :quiet                              for /f "Tokens=*" %%x in ('reg query %1 /V DependOnService^|find /i "winmgmt\"') do (                               set OK=Y                              )                              goto :EOF                              :depend                              set work=%1                              set work=%work:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\=%                              @echo %work%>>%file%                              net stop %work%                              goto :EOF                              :wmi                              net start winmgmt