Batch script to fix wmi - urgent

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
morb
Posts: 9
Joined: 09 May 2012 04:12

Batch script to fix wmi - urgent

#1 Post by morb » 09 May 2012 07:03

Hi
I have this instruction to fix wmi problem:
for %i in ("wbemcomn.dll") do (echo %~$PATH:i)
for %i in ("wmiutils.dll") do (echo %~$PATH:i)
sc config winmgmt start= disabled
cd /D %windir%\system32\wbem
* Check PID in Regedit (My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\CIMOM ->ProcessID
* kill the Process ID Via Task Maneger.
rmdir /s /q repository
rmdir /s /q Logs
mkdir Logs
for /R %i in (*.dll) do (regsvr32 /s %i) \\ Wait for popup message
regsvr32 /s fastprox.dll
for /R %i in (*.exe) do (%i -regserver)
sc config winmgmt start= auto
regsvr32 wbemupgd.dll
net start server && net start workstation && net start AudioSrv && net start termservice

wbemtest.exe
I want to change it to a batch file
How can i do this
* Check PID in Regedit (My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\CIMOM ->ProcessID
* kill the Process ID Via Task Maneger.
probably use the WMI ,what can I do in another way?
Thanks in advance..

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

Re: Batch script to fix wmi - urgent

#2 Post by abc0502 » 09 May 2012 12:28

Hi, Here is Your Code, Didn't Change Any of The Other Command Except The Lines 27 to 30 "Net Command" made every command in single Line and Changed the % to %% and Replaced i to different letters to avoid any problem "just in case"

And Added The Code For Getting The Process ID and Killing It.

Code: Select all

@ECHO OFF
CLS
FOR %%a IN ("wbemcomn.dll") DO Echo %%~$PATH:a
FOR %%b IN ("wmiutils.dll") DO Echo %%~$PATH:b
SC config winmgmt start= disabled
CD /D %windir%\system32\wbem

::  === This Command Is for Getting The Process ID and Killing It From The Task Manager.
SET "reg=HKLM\SOFTWARE\Microsoft\WBEM\CIMOM"
REG EXPORT "%reg%" "%temp%\reg.txt"
Setlocal EnableDelayedExpansion
FOR /F "tokens=3 delims==dword:" %%c IN ('find /I "ProcessID" "%temp%\reg.txt"') DO set hex=%%c
CALL:toDec %hex% PID
TASKKILL /PID %PID%

::  === This Is For Deleting The <reg.txt> Created with the Command "REG EXPORT" Line9.
DEL /F /Q "%temp%\reg.txt"
::  === Ending The Local and Delayed Extension.
ENDLOCAL DisableEelayedExpansion

RMDIR /S /Q Repository
RMDIR /S /Q Logs
MKDIR Logs
FOR /R %%d IN (*.dll) DO Regsvr32 /S %%d
Regsvr32 /S fastprox.dll
FOR /R %%e IN (*.exe) DO %%e -regserver
SC config winmgmt start= auto
Regsvr32 wbemupgd.dll
NET start server
NET start workstation
NET start AudioSrv
NET start termservice

wbemtest.exe

:toDec
::$created 20091203 :$changed 20091203 :$categories Arithmetic,Encoding
::$source http://www.dostips.com
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL
    IF "%~2" NEQ "" (SET %~2=%dec%) ELSE ECHO.%dec%
)
EXIT /b

:: http://www.dostips.com/forum/

The last Part that start from ":toDec" is for converting the hex value of the process ID to a Decimal value that Task Manager use, cause the registry keep the value when exported in hex.

Hope It Work :)

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#3 Post by morb » 09 May 2012 22:53

Hi
It doesn't work fine because at the command taskkill it's output access denied (I told you the taskkill connect to wmi and it's corrupted).
Can you please think about another way to kill the process?

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

Re: Batch script to fix wmi - urgent

#4 Post by foxidrive » 09 May 2012 23:03

morb wrote:Hi
It doesn't work fine because at the command taskkill it's output access denied


Are you running the batch file with elevated privileges?

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#5 Post by morb » 09 May 2012 23:09

yes.
I'm running it locally on the computer with the wmi problem.
(there is no problem to me to kill the process manually).

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

Re: Batch script to fix wmi - urgent

#6 Post by foxidrive » 09 May 2012 23:21

If you run this batch file what happens?


Code: Select all

@echo off
title ZYZ
for /f "tokens=2" %%a in ('tasklist /fi "windowtitle eq ZYZ"') do set pid=%%a

echo TASKKILL /PID %PID%
TASKKILL /PID %PID%

pause

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#7 Post by morb » 09 May 2012 23:28

I got access denied.

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

Re: Batch script to fix wmi - urgent

#8 Post by foxidrive » 09 May 2012 23:50

morb wrote:I got access denied.


At which point? Can you post a screen shot of the dos window?

I'm trying to clarify where the issue is...

What is stopping you from doing it manually?
Does WMIC become corrupted again, and is that because of the file replacement cache in Windows? Is this Windows XP or Win7 etc?

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

Re: Batch script to fix wmi - urgent

#9 Post by abc0502 » 09 May 2012 23:56

Reboot The PC in SafeMode Then Run The Batch Again,
And If It's OK to kill the process Manualy here is the code it wil give u the process ID to kill.
>> Replaced "Taskkill /PID %PID%"
@ECHO OFF
CLS
FOR %%a IN ("wbemcomn.dll") DO Echo %%~$PATH:a
FOR %%b IN ("wmiutils.dll") DO Echo %%~$PATH:b
SC config winmgmt start= disabled
CD /D %windir%\system32\wbem

:: === This Command Is for Getting The Process ID and Killing It From The Task Manager.
SET "reg=HKLM\SOFTWARE\Microsoft\WBEM\CIMOM"
REG EXPORT "%reg%" "%temp%\reg.txt"
Setlocal EnableDelayedExpansion
FOR /F "tokens=3 delims==dword:" %%c IN ('find /I "ProcessID" "%temp%\reg.txt"') DO set hex=%%c
CALL:toDec %hex% PID
Echo %PID%
Pause


:: === This Is For Deleting The <reg.txt> Created with the Command "REG EXPORT" Line9.
DEL /F /Q "%temp%\reg.txt"
:: === Ending The Local and Delayed Extension.
ENDLOCAL DisableEelayedExpansion

RMDIR /S /Q Repository
RMDIR /S /Q Logs
MKDIR Logs
FOR /R %%d IN (*.dll) DO Regsvr32 /S %%d
Regsvr32 /S fastprox.dll
FOR /R %%e IN (*.exe) DO %%e -regserver
SC config winmgmt start= auto
Regsvr32 wbemupgd.dll
NET start server
NET start workstation
NET start AudioSrv
NET start termservice

wbemtest.exe

:toDec
::$created 20091203 :$changed 20091203 :$categories Arithmetic,Encoding
::$source http://www.dostips.com
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL
IF "%~2" NEQ "" (SET %~2=%dec%) ELSE ECHO.%dec%
)
EXIT /b

:: http://www.dostips.com/forum/

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#10 Post by morb » 10 May 2012 00:11

I don't want to do it manually.
I want is all automatic in silent without any user interaction.
I got this in the screen when I run the batch that foxidrive give.
ERROR: Access denied
TASKKILL /PID
ERROR: Invalid syntax. Value expected for '/PID'.
Type "TASKKILL /?" for usage.
Press any key to continue . . .
I'm running win server 2003

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

Re: Batch script to fix wmi - urgent

#11 Post by abc0502 » 10 May 2012 00:42

Can we use a 3rd Party tool?
If so download this tool and put it in the same folder with the batch, And replace the "taskkill line" in the FIRST BATCH with this code in red
it should look like that:
%~dp0\pskill.exe
%~dp0\pskill.exe %PID%


If it worked i can put the batch and the program in one exe file that extract the files and run the batch on click

The Link: http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

EDIT
sorry forgot to say the first line is for running the prgram first in case it wa the first time just to accept the license

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#12 Post by morb » 10 May 2012 01:17

Hi
It's work with pskill
I have just two problems
1. After the pskill command
I got in the next command that the process can not access because it being used by another process
can I need an delay after the pskill?
2.in the command:
FOR /R %%e IN (*.exe) DO %%e -regserver
it run for me the wbemtest.exe
I I don't want any user interaction , how can I skip on reg this exe?
Thanks

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

Re: Batch script to fix wmi - urgent

#13 Post by abc0502 » 10 May 2012 02:02

about the first problem is it the deletion of the reg.txt file or removing the Repository and log files
try add pause after every command and see where the error happen i tested now but don't getting the first error

and what is wbemtest.exe do exactly?

and the second problem what this -regserver do is it regestring the exe files, if so how?
what this command do exactly
FOR /R %%e IN (*.exe) DO %%e -regserver

i tried it manually one by one for the exe files in the directory and nothing happen the gui window that is pend is wbemtest.exe
if u wan't to skip that i don't really think that the command above do any thing usefull

also the last command wbemtest.exe is the same i think u run this at the end to check if every thing is ok now or not if it's ok to skip it i will post the new code

morb
Posts: 9
Joined: 09 May 2012 04:12

Re: Batch script to fix wmi - urgent

#14 Post by morb » 10 May 2012 02:58

Hi
1. I saw that I got this message after the pskill when it try to RMDIR /S /Q Repository
2.I don't need the test so you can skip it in the script

Thx

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

Re: Batch script to fix wmi - urgent

#15 Post by abc0502 » 10 May 2012 03:47

could u check if this file exist on ur pc wbemupgd.dll
when i run the batch it tell that there is a problem with it, when i searched for it couldn't find it.

Post Reply