forked from bmrf/standalone_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repair_wmi.bat
89 lines (78 loc) · 2.87 KB
/
repair_wmi.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
:: Purpose: Rebuilds and repairs WMI on a system
:: Requirements: A broken WMI configuration
:: Author: akp982 at http://community.spiceworks.com/scripts/show/113-rebuild-wmi
:: .bat-wrapped by reddit.com/user/vocatus ( vocatus.gate at gmail ) // PGP key: 0x07d1490f82a211a2
:: Version: 1.0.0 Initial write
:::::::::::::::
:: VARIABLES :: -- Set these to your desired values
:::::::::::::::
:: Set where to save the logfile here
set LOGPATH=%SystemDrive%\Logs
set LOGFILE=%COMPUTERNAME%_WMI_repair.log
::::::::::
:: Prep :: -- Don't change anything in this section
::::::::::
@echo off
SETLOCAL
set SCRIPT_VERSION=1.0.0
set SCRIPT_UPDATED=2015-02-11
:: Get the date into ISO 8601 standard format (yyyy-mm-dd) so we can use it
FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
:::::::::::::
:: EXECUTE ::
:::::::::::::
echo.
echo Rebuilding WMI.....Please wait. > "%LOGPATH%\%LOGFILE%"
echo Rebuilding WMI.....Please wait.
echo.
net stop sharedaccess >> "%LOGPATH%\%LOGFILE%"
net stop winmgmt /y >> "%LOGPATH%\%LOGFILE%"
pushd %SystemRoot%\system32\wbem >> "%LOGPATH%\%LOGFILE%"
for %%i in (*.dll) do RegSvr32 -s %%i
tskill wbemtest /a 2>NUL
scrcons.exe /RegServer
unsecapp.exe /RegServer
wmiadap.exe /RegServer
wmiapsrv.exe /RegServer
wmiprvse.exe /RegServer
start "" wbemtest.exe /RegServer
tskill wbemtest /a 2>NUL
tskill wbemtest /a 2>NUL
del /Q Repository >> "%LOGPATH%\%LOGFILE%"
mofcomp cimwin32.mof >> "%LOGPATH%\%LOGFILE%"
mofcomp cimwin32.mfl >> "%LOGPATH%\%LOGFILE%"
mofcomp rsop.mof >> "%LOGPATH%\%LOGFILE%"
mofcomp rsop.mfl >> "%LOGPATH%\%LOGFILE%"
for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s >> "%LOGPATH%\%LOGFILE%"
for /f %%s in ('dir /b *.mof') do mofcomp %%s >> "%LOGPATH%\%LOGFILE%"
for /f %%s in ('dir /b *.mfl') do mofcomp %%s >> "%LOGPATH%\%LOGFILE%"
mofcomp exwmi.mof >> "%LOGPATH%\%LOGFILE%"
mofcomp -n:root\cimv2\applications\exchange wbemcons.mof >> "%LOGPATH%\%LOGFILE%"
mofcomp -n:root\cimv2\applications\exchange smtpcons.mof >> "%LOGPATH%\%LOGFILE%"
mofcomp exmgmt.mof >> "%LOGPATH%\%LOGFILE%"
net stop winmgmt >> "%LOGPATH%\%LOGFILE%"
net start winmgmt >> "%LOGPATH%\%LOGFILE%"
:: Most aggressive option
winmgmt.exe /resetrepository
:: Less aggressive option
:: winmgmt.exe /salvagerepository /resyncperf
:: Get 64-bit stuff
if exist %SystemRoot%\SysWOW64\wbem (
pushd %SystemRoot%\SysWOW64\wbem
for %%j in (*.dll) do RegSvr32 -s %%j
:: Most aggressive option
winmgmt.exe /resetrepository
:: Less aggressive option
:: winmgmt.exe /salvagerepository /resyncperf
wmiadap.exe /RegServer
wmiprvse.exe /RegServer
popd
)
popd
:: finished
echo.
echo WMI rebuild finished, recommend rebooting now.>> "%LOGPATH%\%LOGFILE%"
echo WMI rebuild finished, recommend rebooting now.
echo.
pause