:: Check for WMI results equal nul value then launch fix
REM
:: Get DNSHOSTNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic OS Get csname /value') DO SET "SysHosts=%%A"
:: Get SYSTEMNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic ComputerSystem Get Model /value') DO SET "SysNames=%%A"
:: Get SERIALNUMBER
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic Bios Get SerialNumber /value') DO SET "SerNumbers=%%A"
:: Get USERNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic ComputerSystem Get UserName /value') DO SET "UserNames=%%A"
:: Get USERNAMECS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get IdentifyingNumber /value') DO SET "UserNamesCS=%%A"
:: Get MANUFACTURERCS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic Bios Get Manufacturer /value') DO SET "ManufacturerCS=%%A"
:: Get VENDORCS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get Vendor /value') DO SET "VendorCS=%%A"
:: Get NAMECS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get Name /value') DO SET "NamesCS=%%A"
::
::
IF /I NOT "%SysHosts%" == "" GOTO END
IF /I NOT "%SysHosts%" == " " GOTO END
::
IF /I NOT "%SysNames%" == "" GOTO END
IF /I NOT "%SysNames%" == " " GOTO END
::
IF /I NOT "%SerNumbers%" == "" GOTO END
IF /I NOT "%SerNumbers%" == " " GOTO END
::
IF /I NOT "%UserNames%" == "" GOTO END
IF /I NOT "%UserNames%" == " " GOTO END
::
IF /I NOT "%UserNamesCS%" == "" GOTO END
IF /I NOT "%UserNamesCS%" == " " GOTO END
::
IF /I NOT "%ManufacturerCS%" == "" GOTO END
IF /I NOT "%ManufacturerCS%" == " " GOTO END
::
IF /I NOT "%VendorCS%" == "" GOTO END
IF /I NOT "%VendorCS%" == " " GOTO END
::
IF /I NOT "%NamesCS%" == "" GOTO END
IF /I NOT "%NamesCS%" == " " GOTO END
::
REM
REM Check Windows Version
::
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_XP
::
ver | findstr /i "5\.2\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_2K3
::
goto ver_ALL_Win
:ver_ALL_Win
:: Run Windows 7 specific commands here
:: Reset Repository WMI repository folder
winmgmt /standalonehost
winmgmt /resetrepository
winmgmt /verifyrepository
REM echo OS Version: Windows 7 (debug line)
goto Start
:ver_2K3
:: Run Windows 2003 specific commands here
:: Reset Repository WMI repository folder
rundll32 wbemupgd, RepairWMISetup
REM echo OS Version: Windows 2003 (debug line)
goto Start
:ver_XP
:: Run Windows XP specific commands here
:: Reset Repository WMI repository folder
rundll32 wbemupgd, UpgradeRepository
REM echo OS Version: Windows XP (debug line)
goto Start
:RenameWMI
::
winmgmt /salvagerepository
::
Echo.
Echo Renaming the WMI repository folder
for /f "tokens=1-8 delims=:/. " %%a in ('echo %date% %time%') do set FileExtension=%%d%%b%%c%%e%%f%%g
ren "%windir%\system32\wbem\Repository" Repository.%FileExtension%.old
ren "%windir%\SysWOW64\wbem\Repository" Repository.%FileExtension%.old
Echo.
Echo Registering WMI DLLs
cd /d %windir%\system32\wbem
for /f %%s in ('dir /b /s *.dll') do echo %%s®svr32 /s %%s
if /i not exist %windir%\SysWOW64\wbem goto :EOF
cd /d %windir%\SysWOW64\wbem
for /f %%s in ('dir /b /s *.dll') do echo %%s®svr32 /s %%s
goto :EOF
:ImportMOF
Echo.
Echo Importing WMI MOF and MFL files
Echo (It's normal for this to take a few minutes)
Echo.
cd /d %windir%\system32\wbem
for /f "delims=" %%s in ('dir /s /b *.mof *.mfl') do echo %%s&mofcomp -autorecover "%%s"
if /i not exist %windir%\SysWOW64\wbem goto :ImportMOFNext
cd /d %windir%\SysWOW64\wbem
for /f "delims=" %%s in ('dir /s /b *.mof *.mfl') do echo %%s&mofcomp -autorecover "%%s"
:ImportMOFNext
Echo.
Echo MOF and MFL file import complete
Echo Verify administrative consoles for installed applications and services
Echo.
goto :EOF
:StopService
Echo.
Echo Disabling and stopping the %1 service
sc config %1 start= disabled
if /i {%errorlevel%}=={9009} echo SC tool not installed or not available here. Exiting...&goto :End
net stop %1 /y
sc query %1 | find /i "running"
if /i {%errorlevel%}=={0} echo Couldn't stop the %1 service. Exiting...&goto :End
goto :EOF
:StartService
Echo.
Echo Starting %1
sc config %1 start= demand
net start %1
sc config %1 start= auto
goto :EOF
:End
Echo Script ran to completion
:EOF
REM End OF File
sc config iphlpsvc start= auto
sc start iphlpsvc
sc config NACAgent start= auto
sc start NACAgent
sc config RemoteRegistry start= auto
sc start RemoteRegistry
sc config UI0Detect start= auto
sc start UI0Detect
sc config DcomLaunch start= auto
sc start DcomLaunch
sc config RpcEptMapper start= auto
sc start RpcEptMapper
sc config RpcSs start= auto
sc start RpcSs
sc config eventlog start= auto
sc start eventlog
sc config Winmgmt start= auto
sc start Winmgmt
sc config "OCS Inventory Service" start= auto
sc start "OCS Inventory Service"
@echo off
cls
:: Check for WMI results equal nul value then launch fix =%%A"
REM
:: Get DNSHOSTNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic OS Get csname /value') DO SET "SysHosts=%%A"
:: Get SYSTEMNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic ComputerSystem Get Model /value') DO SET "SysNames=%%A"
:: Get SERIALNUMBER
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic Bios Get SerialNumber /value') DO SET "SerNumbers=%%A"
:: Get USERNAME
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic ComputerSystem Get UserName /value') DO SET "UserNames=%%A"
:: Get USERNAMECS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get IdentifyingNumber /value') DO SET "UserNamesCS=%%A"
:: Get MANUFACTURERCS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic Bios Get Manufacturer /value') DO SET "ManufacturerCS
:: Get VENDORCS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get Vendor /value') DO SET "VendorCS=%%A"
:: Get NAMECS
FOR /F "TOKENS=2 DELIMS='='" %%A IN ('wmic csproduct get Name /value') DO SET "NamesCS=%%A"
::
::
IF /I NOT "%SysHosts%" == "" GOTO END
IF /I NOT "%SysHosts%" == " " GOTO END
::
IF /I NOT "%SysNames%" == "" GOTO END
IF /I NOT "%SysNames%" == " " GOTO END
::
IF /I NOT "%SerNumbers%" == "" GOTO END
IF /I NOT "%SerNumbers%" == " " GOTO END
::
IF /I NOT "%UserNames%" == "" GOTO END
IF /I NOT "%UserNames%" == " " GOTO END
::
IF /I NOT "%UserNamesCS%" == "" GOTO END
IF /I NOT "%UserNamesCS%" == " " GOTO END
::
IF /I NOT "%ManufacturerCS%" == "" GOTO END
IF /I NOT "%ManufacturerCS%" == " " GOTO END
::
IF /I NOT "%VendorCS%" == "" GOTO END
IF /I NOT "%VendorCS%" == " " GOTO END
::
IF /I NOT "%NamesCS%" == "" GOTO END
IF /I NOT "%NamesCS%" == " " GOTO END
::
REM
REM Check Windows Version
::
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_XP
::
ver | findstr /i "5\.2\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_2K3
::
goto ver_ALL_Win
:ver_ALL_Win
:: Run Windows 7 specific commands here
:: Reset Repository WMI repository folder
winmgmt /standalonehost
winmgmt /resetrepository
winmgmt /verifyrepository
REM echo OS Version: Windows 7 (debug line)
goto Start
:ver_2K3
:: Run Windows 2003 specific commands here
:: Reset Repository WMI repository folder
rundll32 wbemupgd, RepairWMISetup
REM echo OS Version: Windows 2003 (debug line)
goto Start
:ver_XP
:: Run Windows XP specific commands here
:: Reset Repository WMI repository folder
rundll32 wbemupgd, UpgradeRepository
REM echo OS Version: Windows XP (debug line)
goto Start
:Start
call :StopService WSRM
call :StopService tmlisten
call :StopService iphlpsvc
call :StopService winmgmt
call :RenameWMI
call :StartService winmgmt
call :StartService iphlpsvc
call :StartService tmlisten
call :StartService WSRM
call :ImportMOF
goto :End
:RenameWMI %%d%%b% %c%%e%% f%%g \system32\ wbem\Repository " Repository. %FileExtension% .old \SysWOW64\ wbem\Repository " Repository. %FileExtension% .old
::
winmgmt /salvagerepository
::
Echo.
Echo Renaming the WMI repository folder
for /f "tokens=1-8 delims=:/. " %%a in ('echo %date% %time%') do set FileExtension=
ren "%windir%
ren "%windir%
Echo. \system32\ wbem
Echo Registering WMI DLLs
cd /d %windir%
for /f %%s in ('dir /b /s *.dll') do echo %%s®svr32 /s %%s
if /i not exist %windir% \SysWOW64\ wbem goto :EOF \SysWOW64\ wbem
cd /d %windir%
for /f %%s in ('dir /b /s *.dll') do echo %%s®svr32 /s %%s
goto :EOF
:ImportMOF \system32\ wbem
Echo.
Echo Importing WMI MOF and MFL files
Echo (It's normal for this to take a few minutes)
Echo.
cd /d %windir%
for /f "delims=" %%s in ('dir /s /b *.mof *.mfl') do echo %%s&mofcomp -autorecover "%%s"
if /i not exist %windir% \SysWOW64\ wbem goto :ImportMOFNext \SysWOW64\ wbem
cd /d %windir%
for /f "delims=" %%s in ('dir /s /b *.mof *.mfl') do echo %%s&mofcomp -autorecover "%%s"
:ImportMOFNext
Echo.
Echo MOF and MFL file import complete
Echo Verify administrative consoles for installed applications and services
Echo.
goto :EOF
:StopService }=={9009} echo SC tool not installed or not available here. Exiting...&goto :End
Echo.
Echo Disabling and stopping the %1 service
sc config %1 start= disabled
if /i {%errorlevel%
net stop %1 /y
sc query %1 | find /i "running"
if /i {%errorlevel%}=={0} echo Couldn't stop the %1 service. Exiting...&goto :End
goto :EOF
:StartService
Echo.
Echo Starting %1
sc config %1 start= demand
net start %1
sc config %1 start= auto
goto :EOF
:End
Echo Script ran to completion
:EOF
REM End OF File
sc config iphlpsvc start= auto
sc start iphlpsvc
sc config NACAgent start= auto
sc start NACAgent
sc config RemoteRegistry start= auto
sc start RemoteRegistry
sc config UI0Detect start= auto
sc start UI0Detect
sc config DcomLaunch start= auto
sc start DcomLaunch
sc config RpcEptMapper start= auto
sc start RpcEptMapper
sc config RpcSs start= auto
sc start RpcSs
sc config eventlog start= auto
sc start eventlog
sc config Winmgmt start= auto
sc start Winmgmt
sc config "OCS Inventory Service" start= auto
sc start "OCS Inventory Service"
wmic Bios Get SerialNumber