Windows批处理文件,用于无效的Microsoft更新

时间:2016-07-18 19:46:23

标签: batch-file wmic errorlevel hotfix qfe

创建一个Windows批处理文件时,我很震惊,该文件只指示我的计算机/ Windows服务器上是否安装了无效的KB文章。

这就是我现在所处的位置,

脚本:

@ECHO OFF
WMIC QFE GET HOTFIXID>%~dp0QFE_list.txt
FOR /f "delims=," %%a IN (%~dp0Patch_List.txt) DO (
    CALL :PATCH_LIST %%a
)
GOTO :EOF

:PATCH_LIST
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%1">NULL.txt
IF %ERRORLEVEL% EQU 0 ECHO %1: INSTALLED
IF %ERRORLEVEL% NEQ 0 (
ECHO FIND %1
FIND /C "%1" %~dp0QFE_List.txt>NULL.txt
IF ERRORLEVEL 0 ECHO %1: QFE INSTALLED
IF ERRORLEVEL 1 ECHO %1: **** NOT INSTALLED! ****
)

当前输出:---------- C:\ USERS \ PVENK17 \ DESKTOP \ TEST \ QFE_LIST.TXT:1

所需输出::已安装

输入文件内容:KB3057839,KB3002657

问题:

即使它适用于1 KBarticle。当我在输入文件中放置多于1时,它不起作用。

请帮我解决这个问题。

由于 普拉香特

3 个答案:

答案 0 :(得分:0)

我可以通过更改输入文件格式来完成这项工作:每行1 KB

KB3057839
KB3002657

然后,只需删除“delims”内容,它适用于多个项目。不确定最后一行的逻辑。它似乎说“已安装/未安装”

然后BTW将您的命令重定向到NUL,以避免创建无用的文件。

@ECHO OFF
WMIC QFE GET HOTFIXID>%~dp0QFE_list.txt
FOR /f %%a IN (%~dp0Patch_List.txt) DO (
    CALL :PATCH_LIST %%a
)
GOTO :EOF

:PATCH_LIST
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "%1">NUL
IF %ERRORLEVEL% EQU 0 ECHO %1: INSTALLED
IF %ERRORLEVEL% NEQ 0 (
ECHO FIND %1
FIND /C "%1" %~dp0QFE_List.txt>NUL
IF ERRORLEVEL 0 ECHO %1: QFE INSTALLED
IF ERRORLEVEL 1 ECHO %1: **** NOT INSTALLED! ****
)

答案 1 :(得分:0)

经过更多的调试后我编写了这段代码,我知道它不是理想的解决方案,但它可以正常工作

代码:

@ECHO OFF
title IllegalPatchCheck

echo Select a server. (AW/PG)
set /p server=

IF /i "%server%"=="AW" goto AdminWorkstation
IF /i "%server%"=="PG" goto PeripheralGateway

echo Invalid Input.
goto commonexit

:AdminWorkstation

WMIC QFE GET HOTFIXID>%~dp0QFE_list.txt

find /c "KB3057839" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 ECHO KB3057839  NOT Found
if %errorlevel% neq 1 ECHO KB3057839 Found

find /c "KB3058515" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 ECHO KB3057839  NOT Found
if %errorlevel% neq 1 echo KB3058515 Found

find /c "KB3059317" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 echo KB3059317 NOT found
if %errorlevel% neq 1 echo KB3059317 Found

find /c "KB3063858" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 echo KB3063858 NOT found
if %errorlevel% neq 1 echo KB3063858 Found

goto commonexit

:PeripheralGateway

WMIC QFE GET HOTFIXID>%~dp0QFE_list.txt

find /c "KB2984972" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 echo KB2984972 NOT Found
if %errorlevel% neq 1 echo KB2984972 Found

find /c "KB3046049" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 echo KB3046049 NOT Found
if %errorlevel% neq 1 echo KB3046049 Found

find /c "KB3002657" %~dp0QFE_list.txt>nul
if %errorlevel% equ 1 echo KB3002657 NOT Found
if %errorlevel% neq 1 echo KB3002657 Found

goto commonexit

:commonexit
del /q /f %~dp0QFE_list.txt >nul
pause

由于 普拉香特

答案 2 :(得分:0)

@echo off
title HOTFIXID_KB_FOUND
setlocal enabledelayedexpansion
cd /d "%~dp0"
for /f %%A in (KB_list.txt) do (
wmic qfe get hotfixid |findstr /i "%%A"
if !errorlevel! equ 0 echo %%A: ****INSTALLED****
if !errorlevel! equ 1 echo %%A: NOT INSTALLED
)
pause
在我的情况下,

KB_list.txt 是导致BSOD的有害更新列表。当然,您可以自动删除,但并非总是 wusa.exe 有时需要 dism.exe

使用wusa.exe删除的示例

wusa.exe /uninstall /kb:3065987 /quiet /norestart

使用dism.exe删除的示例

DISM /Online /Get-Packages /Format:Table
DISM /Online /Remove-Package /PackageName:Package_for_KB3045999~31bf3856ad364e35~amd64~~6.1.1.1