Batch script to fix wmi - urgent

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Batch script to fix wmi - urgent

#16 Post by foxidrive » 10 May 2012 05:17

morb wrote: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


The error comes before taskkill is executed and could be a corrupt tasklist file.
You may say that tasklist uses WMIC but I think that is unlikely.

You can see in the previous text that taskkill printed the help screen ok

Try this batch file and paste the screen output

Code: Select all

@echo off
echo ---
title ZYZ
echo A
tasklist /fi "windowtitle eq ZYZ"
echo B
pause

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

Re: Batch script to fix wmi - urgent

#17 Post by morb » 10 May 2012 05:32

I found wbemupgd.dll on the computer.
What the connection?

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

Re: Batch script to fix wmi - urgent

#18 Post by abc0502 » 10 May 2012 05:34

OK i will post the code in few moments

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

Re: Batch script to fix wmi - urgent

#19 Post by abc0502 » 10 May 2012 05:36

If You want it to be all "the batch and the pskill" in one exe self extracting file tell me .

Code: Select all

@ECHO OFF
CLS

Color 0f
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Checking Files " &echo:
CALL :C 0a "=====================================" &echo:
FOR %%a IN ("wbemcomn.dll") DO Echo %%~$PATH:a
FOR %%b IN ("wmiutils.dll") DO Echo %%~$PATH:b
CALL :C 0c "Done." &echo:
echo. &echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "WinMgmt Service Disabled " &echo:
CALL :C 0a "=====================================" &echo:
SC config winmgmt start= disabled >nul
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Changing to wbem Folder" &echo:
CALL :C 0a "=====================================" &echo:
CD /D %windir%\system32\wbem
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Retrieving Process PID" &echo:
CALL :C 0a "=====================================" &echo:
::  === This Command Is for Getting The Process ID and Killing It From The Task Manager.
IF EXIST "%temp%\reg.txt" DEL /F /Q "%temp%\reg.txt" >nul
SET "reg=HKLM\SOFTWARE\Microsoft\WBEM\CIMOM"
REG EXPORT "%reg%" "%temp%\reg.txt" >nul
Setlocal EnableDelayedExpansion
FOR /F "tokens=3 delims==dword:" %%c IN ('find /I "ProcessID" "%temp%\reg.txt"') DO set hex=%%c
CALL:toDec %hex% PID
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Terminating Process" &echo:
CALL :C 0a "=====================================" &echo:
"%~dp0\pskill.exe" >nul
"%~dp0\pskill.exe" %PID% >nul
ENDLOCAL DisableEelayedExpansion
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Removing Repository and Logs Folders" &echo:
CALL :C 0a "=====================================" &echo:
RMDIR /S /Q Repository >nul
RMDIR /S /Q Logs >nul
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0E "Continuing in "3" Sec"
echo.&echo.
Ping Localhost -n 5 >nul
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Creating Log Folder" &echo:
CALL :C 0a "=====================================" &echo:
MKDIR Logs >nul
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Registring DLL Files" &echo:
CALL :C 0a "=====================================" &echo:
FOR /R %%d IN (*.dll) DO Regsvr32 /S %%d
Regsvr32 /S fastprox.dll
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "WinMgmt Service Enabled" &echo:
CALL :C 0a "=====================================" &echo:
SC config winmgmt start= auto
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Registring Wbemtest.dll File" &echo:
CALL :C 0a "=====================================" &echo:
Regsvr32 wbemupgd.dll
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Starting Services" &echo:
CALL :C 0a "=====================================" &echo:
NET start server
NET start workstation
NET start AudioSrv
NET start termservice
CALL :C 0c "Done." &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0d "All Operations Completed Successfully" &echo:
CALL :C 0a "=====================================" &echo:&echo:&echo:
PAUSE >nul

:toDec
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL
    IF "%~2" NEQ "" (SET %~2=%dec%) ELSE ECHO.%dec%
)
EXIT /b

:C
setlocal
set "file=%~2"
set "file=%file:^^=^%"
for /f "delims=#" %%a in ('"prompt #$H# &echo on &for %%b in (1) do rem"') do set "BSB=%%a"
pushd "%temp%"
>"%file%X" set /p "=%BSB%%BSB%"<nul
findstr /a:%1 . "%file%X" nul
del "%file%X" >nul 2>&1
popd
endlocal
goto :eof
:: http://www.dostips.com/forum/

Hope u like it and problem post here
Last edited by abc0502 on 10 May 2012 07:00, edited 1 time in total.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Batch script to fix wmi - urgent

#20 Post by Squashman » 10 May 2012 05:52

morb wrote: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

Of course you are going to get an error if you don't put a PID number after the /PID switch!

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

Re: Batch script to fix wmi - urgent

#21 Post by foxidrive » 10 May 2012 05:57

The problem is that whatever caused the 'access denied' messages also stopped the PID from being set.

The answer seems to be either cmd.exe or tasklist

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

Re: Batch script to fix wmi - urgent

#22 Post by abc0502 » 10 May 2012 06:05

he used the pskill program and it worked for him now

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

Re: Batch script to fix wmi - urgent

#23 Post by morb » 10 May 2012 06:14

some problems:
1. after terminating process x
I got the error:
'c:\Document' is not recognized like an external...
2. After removing repository
I got the error that it being used by another program
3.After requesting wbemtest.dll Filex
I got a pop-up about the registry of wbemupgd.dll

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

Re: Batch script to fix wmi - urgent

#24 Post by abc0502 » 10 May 2012 06:24

morb wrote:some problems:
1. after terminating process x
I got the error:
'c:\Document' is not recognized like an external...
2. After removing repository
I got the error that it being used by another program
3.After requesting wbemtest.dll Filex
I got a pop-up about the registry of wbemupgd.dll


1- Add the quote in red to the code to fix problem #1
"%~dp0\pskill.exe" >nul
"%~dp0\pskill.exe" %PID% >nul


2- This error i don't know about now but give me some time

3- this is the same pop up that come to me check to see it this file exist in %windir%\system32\wbem and if not there give me the location of it and if possible give me the entire message tha come to u

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

Re: Batch script to fix wmi - urgent

#25 Post by abc0502 » 10 May 2012 06:45

Is the pop error like this [img][img]http://www.freeimagehosting.net/t/puyzd.jpg[/img][/img]
this mean that the file isn't in the same directory so give me the location on ur pc

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

Re: Batch script to fix wmi - urgent

#26 Post by abc0502 » 10 May 2012 07:09

Here is The FINAL Code
====================
--> The Pop message that appear it only happend in win7 but XP it say registring successfull so i made the batch check if the windows running xp it run the command if win7 it skip the command.

--> The Repository folder will be deleted the problem was in the command sc at the begining it should be net stop command and if didn't work just go to the directory : %windir%\system32\wbem and right click and take ownership of the file then run the batch again.

--> The Terminating Process command it should be putted between quotes

--> Added extra option that work for ex only it will re-write missing files but will require the instalation cd, the option will appear at the end of the batch when done.

Changes mad in Green
The Code:
@ECHO OFF
CLS
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a" )

Color 0f
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Checking Files"&echo:
CALL :C 0a "=====================================" &echo:
FOR %%a IN ("wbemcomn.dll") DO Echo %%~$PATH:a
FOR %%b IN ("wmiutils.dll") DO Echo %%~$PATH:b
CALL :C 0c "Done" &echo:
echo. &echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "WinMgmt Service Disabled " &echo:
CALL :C 0a "=====================================" &echo:
Echo Y|net stop winmgmt >nul
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Changing to wbem Folder" &echo:
CALL :C 0a "=====================================" &echo:
CD /D %windir%\system32\wbem
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Retrieving Process PID" &echo:
CALL :C 0a "=====================================" &echo:
IF EXIST "%temp%\reg.txt" DEL /F /Q "%temp%\reg.txt" >nul
SET "reg=HKLM\SOFTWARE\Microsoft\WBEM\CIMOM"
REG EXPORT "%reg%" "%temp%\reg.txt" >nul
FOR /F "tokens=3 delims==dword:" %%c IN ('find /I "ProcessID" "%temp%\reg.txt"') DO set hex=%%c
CALL:toDec %hex% PID
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Terminating Process" &echo:
CALL :C 0a "=====================================" &echo:
"%~dp0pskill.exe" %PID% >nul
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Removing Repository and Logs Folders" &echo:
CALL :C 0a "=====================================" &echo:
RMDIR /S /Q Repository >nul
RMDIR /S /Q Logs >nul
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0E "Continuing in "3" Sec"
echo.&echo.
Ping Localhost -n 4 >nul
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Creating Log Folder" &echo:
CALL :C 0a "=====================================" &echo:
MKDIR Logs >nul
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Registring DLL Files" &echo:
CALL :C 0a "=====================================" &echo:
FOR /R %%d IN (*.dll) DO Regsvr32 /s %%d
Regsvr32 /S fastprox.dll
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "WinMgmt Service Enabled" &echo:
CALL :C 0a "=====================================" &echo:
Echo Y|net start winmgmt
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Registring Wbemtest.dll File" &echo:
CALL :C 0a "=====================================" &echo:
For /F "skip=1 tokens=3" %%a IN ('ver') DO (
If %%a==[Version ( goto gg
) Else (
if %%a==XP Regsvr32 wbemupgd.dll )
)

CALL :C 0c "Done" &echo:
echo.&echo.

:gg
CALL :C 0a "=====================================" &echo:
CALL :C 0b "Starting Services" &echo:
CALL :C 0a "=====================================" &echo:
NET start server >nul
NET start workstation >nul
NET start AudioSrv >nul
NET start termservice >nul
CALL :C 0c "Done" &echo:
echo.&echo.
CALL :C 0a "=====================================" &echo:
CALL :C 0d "Re-building WMI Completed " &echo:
CALL :C 0a "=====================================" &echo:&echo:&echo:

:skip
Call :C 07 "For Windows XP"&echo:
CALL :C 0a "Press " &call :C 0c "R " &call :C 0a "to restor missing files, or " &call :C 0a "Press " &call :C 0c "X " &call :C 0a "to Close" &echo:
Set "cho="
Set /p "cho=>"
If not defined cho cls & goto skip
If /i %cho%==r goto Missing
If /i %cho%==x goto eof
MSG * "Invalid Choice"
cls
goto skip


:Missing
cls
echo:&echo:
Call :C 0F "This will Require the Installation CD to Replace Missing Files" &echo:&echo:
Call :C 07 " Make The CD Ready and Insert when Prompt" &echo:&echo:
pause
start rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf


:toDec
SETLOCAL
set /a dec=0x%~1
( ENDLOCAL
IF "%~2" NEQ "" (SET %~2=%dec%) ELSE ECHO.%dec%
)
EXIT /b

:C
echo off
cd %temp%
<nul set /p "=%DEL%" >> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof


:eof
Exit

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

Forgot to say when run on windows XP the each line that appear in CMD window end up with ":X . ." i think it's because of the color function but on windows 7 it work fine sorry about that. :)
If u wan't this batch with the pskill tool in one exe file pm me and i will send u a link as soon as i recive ur message

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

Re: Batch script to fix wmi - urgent

#27 Post by mor.bas » 28 May 2012 11:38

Hi

I got this Message Box:

Image

And it's need the user to press OK.

I don't want any user interaction.

Thanks in advance...

[edit aGerman]fixed the link[/edit]

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

Re: Batch script to fix wmi - urgent

#28 Post by aGerman » 28 May 2012 12:18

There is a silent mode for RegSvr32 using the switch /s

Regards
aGerman

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

Re: Batch script to fix wmi - urgent

#29 Post by mor.bas » 29 May 2012 04:06

Hi

It's work silently now.

I have more understanding ques....

I changed the script

Rem PAUSE >nul

(make this line remark).

And I got this error:

Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).

What's the problem?

Second,In the end of the script there is this section:

:C
setlocal
set "file=%~2"
set "file=%file:^^=^%"
for /f "delims=#" %%a in ('"prompt #$H# &echo on &for %%b in (1) do rem"') do set "BSB=%%a"
pushd "%temp%"
>"%file%X" set /p "=%BSB%%BSB%"<nul
findstr /a:%1 . "%file%X" nul
del "%file%X" >nul 2>&1
popd
endlocal
goto :eof

What does this mean?

Thanks in advance....

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

Re: Batch script to fix wmi - urgent

#30 Post by aGerman » 29 May 2012 10:05

The error message is a typical mismatch of set /a, probably caused in function :toDec. Write an echo %~1 in the beginning of that function and tell us what output you get. I'm virtually certain that it has nothing to do with the commented pause command.

The subroutine :C is a tricky piece of code that enables partially colored output.

Regards
aGerman

Post Reply