Re: Batch script to fix wmi - urgent
Posted: 03 Jun 2012 01:16
I got for the command that you ask:
00000
00000
A Forum all about DOS Batch
https://www.dostips.com/forum/
mor.bas wrote:I want to add to the script a wmi qeury (wmic) in the begining and if it success to go out the script.
Code: Select all
Echo Y|net stop winimgmt
Code: Select all
@echo off
cls
mode 65,55
Color 0A
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Checking Files" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
FOR %%a IN ("wbemcomn.dll") DO Echo %%~$PATH:a
FOR %%b IN ("wmiutils.dll") DO Echo %%~$PATH:b
Call :color 0C "Done" end&echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Disabling WinMgmt Service" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
SET /P ".=Service SharedAccess stoped."<nul &echo.
SET /P ".=Service WinMgmt stopped."<nul &echo.
sc stop sharedaccess >nul
sc stop winmgmt >nul
CALL :color 0c "Done" &echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Changing to wbem Folder" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
SET /P ".=Current Directory is :"<nul &echo.
SET /P ".= %windir%\system32\wbem"<nul &echo.
CD /D %windir%\system32\wbem
CALL :color 0c "Done" &echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Retrieving Process PID" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
setlocal
SET "reg=HKLM\SOFTWARE\Microsoft\WBEM\CIMOM"
REG QUERY "%reg%" /v "ProcessID" >nul
:: The delims is a tab not spaces so if the code failed you should check the delims and repalce the space with "TAB"
FOR /F "skip=4 tokens=3 delims= " %%c IN ('REG QUERY "%reg%" /v "ProcessID"') DO set hex=%%c
Call :toDec %hex:~2% PID
SET /P ".=The PID Process is:"<nul &Call :color 0b " %PID%" end&echo.
Call :color 0C "Done" end&echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Terminating Process" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
IF %PID% NEQ 0 (
IF Exist "%~dp0pskill.exe" ( "%~dp0pskill.exe" %PID% >nul
) Else ( Call :color 0B "Can't Kill Process %PID%, PSkill.exe missing" end&echo. &Call :color 03 "Press any key to exit" end&echo.&pause >nul &Exit )
) Else ( Call :color 0b "Service not Exist" end &echo. )
Call :color 0C "Done" end&echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Removing Repository and Logs Folders" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
SET /P ".=Folder : Repository Removed."<nul &echo.
SET /P ".=Folder : Logs Removed."<nul &echo.
RMDIR /S /Q Repository >nul
RMDIR /S /Q Logs >nul
Call :color 0C "Done" end&echo.
CALL :color 0E "Continuing in "3" Sec" end&echo.
Ping Localhost -n 4 >nul
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Registring DLL Files" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
FOR /R %%d IN (*.dll) DO Regsvr32 /s %%d
Regsvr32 /s fastprox.dll
Call :color 0C "Done" end&echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Enabling Stopped Services" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
SET /P ".=Service SharedAccess started."<nul &echo.
SET /P ".=Service WinMgmt started."<nul &echo.
sc start sharedaccess >nul
sc start winmgmt >nul
CALL :color 0c "Done" &echo.&echo.&echo.
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " Registring Wbemtest.dll files" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
For /F "skip=1 tokens=3" %%a IN ('ver') DO (
If %%a==[Version goto skip1
if %%a==XP Regsvr32 /s wbemupgd.dll
)
CALL :color 0c "Done" &echo.&echo.&echo.
goto skip2
:skip1
Call :color 0F "========================================" end&echo.
Call :color 0F "=" &Call :color 0E " starting stopped Services" end &Call :color 0F " =" end&echo.
Call :color 0F "========================================" end&echo.
NET start server >nul
NET start workstation >nul
NET start AudioSrv >nul
NET start termservice >nul
CALL :color 0c "Done" &echo.&echo.&echo.
pause
Exit /B
:skip2
echo.&echo.&echo.
Call :color 07 "To Repair Missing Files in Windows Press" &Call :color 0b " R" end&echo.
Call :color 07 "Or" &Call :color 0C " X" &Call :color 07 " To Exit" end&echo.
Set "cho="
Set /p "cho=>"
If not defined cho cls & goto skip2
If /i %cho%==r goto Missing
If /i %cho%==x Exit
MSG * "Invalid Choice"
cls
goto skip2
:Missing
cls
echo:&echo:
mode 75,55
Call :color 07 "This will Require the Windows Installation CD to Replace Missing Files" &echo.&echo.
Call :color 07 " Make The Windows CD Ready and Insert when Prompted" &echo:&echo.
pause
start rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf
Exit /B
:toDec
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL
IF "%~2" NEQ "" (SET %~2=%dec%) ELSE ECHO.%dec%
)
exit /b
:color
set /p ".= " > "%~2" <nul
findstr /v /a:%1 /R "^$" "%~2" nul 2>nul
set /p ".=" <nul
if "%3" == "end" set /p ".= " <nul
del "%~2" >nul 2>nul
exit /b
Code: Select all
>SET /P ".=Service SharedAccess stoped."<nul &echo.
Service SharedAccess stoped.
>
Code: Select all
>echo.Service SharedAccess stoped.
Service SharedAccess stoped.
>
Code: Select all
>echo. &<nul set /p "=Service SharedAccess stoped."
Service SharedAccess stoped.
>