Batch script to fix wmi - urgent

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Batch script to fix wmi - urgent

#31 Post by mor.bas » 03 Jun 2012 01:16

I got for the command that you ask:

00000

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch script to fix wmi - urgent

#32 Post by aGerman » 03 Jun 2012 05:14

Strange. Even if 00000 should be always the wrong value it should not output the error message.
set /a dec=0x00000 is a legal expression and would calculate a decimal 0. But since the "system idle process" has always PID 0 something must be wrong in the temporary reg.txt I guess.

Sorry but I can't help. I would sit in front of your computer to find the error. Can't do that from the distance.

Regards
aGerman

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch script to fix wmi - urgent

#33 Post by abc0502 » 03 Jun 2012 17:05

hi, the error of converting the hex to dec as aGerman said,
and if it worked with u the first time see what changes u made beside the Rem Pause >nul part,
if no more changes u made, check to see if the reg.txt file exist in the %temp% directory and delete it and run it again if worked that mean the deletion of this file fail in the script.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Batch script to fix wmi - urgent

#34 Post by mor.bas » 06 Jul 2012 05:34

I want to add to the script a wmi qeury (wmic) in the begining and if it success to go out the script.
(I want it always to run and fix the problem only if it's necessary).
Thanks...

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Batch script to fix wmi - urgent

#35 Post by mor.bas » 22 Jul 2012 08:02

Hi
It's seems that the deletion of the file(reg.txt)
didn't succeed what I can do in order to fix it?
Thanks in advance...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to fix wmi - urgent

#36 Post by foxidrive » 22 Jul 2012 08:27

What code are you using?

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Batch script to fix wmi - urgent

#37 Post by mor.bas » 22 Jul 2012 12:05

The one that abc0502 wrote.
see on page 2.
In genarl it working just the delete reg.txt not working and i get the error like
i mention before.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to fix wmi - urgent

#38 Post by foxidrive » 22 Jul 2012 12:55

Add a line to delete the "%temp%\reg.txt" file.

I didn't see you mention any other error in your last few posts. Is there another issue?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to fix wmi - urgent

#39 Post by foxidrive » 22 Jul 2012 12:58

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.



At the start you could do something like this:

@echo off
WMIC query
If %result% EQU fail (
the rest of the batch file here








to here
)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch script to fix wmi - urgent

#40 Post by abc0502 » 22 Jul 2012 14:00

I re-tested again there is an error when trying to stop
The command

Code: Select all

Echo Y|net stop winimgmt

is not working for some reason, it refuse to take the Y as an input

and the process PID after converting to dec is 0, there is no problem in the reg.txt file it's deleted every time you run the batch i think the proplem is that the service is not exit

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch script to fix wmi - urgent

#41 Post by abc0502 » 22 Jul 2012 16:03

I Modified the Final Batch and replaced few commands, removed the reg.txt now it will get the process ID directly from the command line and set it, changed the color fiunction try it and give us a feedback:

NOTE
This code has been modified
NOTE PLEASE: in line 35 "the for loop" the delims should be a TAB not a spaces so delete the space and then press the tab botton after you copy the code to your PC

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

Edit
some time when you run the code you will get the process id 0 close the batch and wait for few moments then run it again, the process has a recovery time to fix it's process id i think, see the registry key from the regedit command
Last edited by abc0502 on 23 Jul 2012 03:12, edited 5 times in total.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Batch script to fix wmi - urgent

#42 Post by mor.bas » 22 Jul 2012 23:42

That what I got on the screen now:
========================================
= Checking File =
========================================
C:\WINDOWS\system32\wbem\wbemcomn.dll
C:\WINDOWS\system32\wbem\wmiutils.dll
Done


========================================
= Disabling WinMgmt Servic =
========================================
Service SharedAccess stoped.
Service WinMgmt stopped.
Done:


========================================
= Changing to wbem Folde =
========================================
Current Directory is :
C:\WINDOWS\system32\wbem
Done:


========================================
= Retrieving Process PI =
========================================
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
The PID Process is:The system cannot find the path specified.

Done


========================================
= Terminating Proces =
========================================
0 was unexpected at this time.

C:\WINDOWS\system32\wbem>
C:\WINDOWS\system32\wbem>^A

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch script to fix wmi - urgent

#43 Post by abc0502 » 23 Jul 2012 02:44

Sorry for the mistakes i don't know what happend but the code i bosted in this form is differant from tha one i have in my pc, I reposted again.

however, i some times get the PID number 0 and after afew times i get it 1664 or something like that, i don't know why :?:

I thinks the code was giving errors because i used the quote tag not the code tag to input my code and the spaces was deleted, sorry :oops:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch script to fix wmi - urgent

#44 Post by abc0502 » 23 Jul 2012 03:08

BIG NOTE:
It seems that the form code tag can't show the "TAB" so, After you Copy the Code to your pc
GOTO LINE 35 "the foor loop" and in the delims delete the exist space and the press the "TAB" botton in the keyboard and the code should work fine

The Delims should be a TAB not a Space

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Batch script to fix wmi - urgent

#45 Post by Ed Dyreen » 23 Jul 2012 04:45

'
Hi abc0502,

Code: Select all

>SET /P ".=Service SharedAccess stoped."<nul &echo.
Service SharedAccess stoped.

>
The nice thing about 'set /p' is that it doesn't adds a linefeed, but then you undo it with an 'echo.', you could just have written:

Code: Select all

>echo.Service SharedAccess stoped.
Service SharedAccess stoped.

>
how about

Code: Select all

>echo. &<nul set /p "=Service SharedAccess stoped."

Service SharedAccess stoped.
>
ps: Did you mean stoped ?, or stopped :)

Post Reply