Here's a simple script that reads a list.txt file for KB patches and queries local machine using WMIC to see if its installed
@echo on
setlocal enabledelayedexpansion
for /f %%i in (list.txt) do (
wmic qfe get hotfixid |findstr /i "%%i"
if %errorlevel% equ 0 @echo %%i found
)
I am always getting %errorlevel% 0 .. why?
Here's sample output
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB961371"
if 0 EQU 1
)
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2584146"
if 0 EQU 1
)
KB2584146
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2585542"
if 0 EQU 1
)
KB2585542
The second and third time it should be zero and it is but the first time it doesn't find the patch but still returns zero.
Thanks in advance for help!
WMIC not returning the right errorlevel
Moderator: DosItHelp
Re: WMIC not returning the right errorlevel
Try this:
Code: Select all
@echo on
setlocal enabledelayedexpansion
for /f %%i in (list.txt) do (
wmic qfe get hotfixid |findstr /i "%%i"
if !errorlevel! equ 0 @echo %%i found
)
Re: WMIC not returning the right errorlevel
Or, if wmic is known to not return negative errorlevels, replace "if %errorlevel% equ 0" with "if not errorlevel 1".
Re: WMIC not returning the right errorlevel
Thanks foxidrive. !errorlevel! worked. Even though I cannot see the output (it just prints !errorlevel! on screen when echo is on) it apparently picks up the right patches.