我一直试图使一个批处理文件正常工作,但是没有成功;也许有人可以帮忙。 我有一个批处理文件,该文件读取一个文件夹中的文本文档,该文件名为KB-list.txt。whithc是要扫描的Window KB的列表,如果要卸载的PC上有这些文件。
请找到我在下面创建的代码,当发现不起作用的代码时,搜索会很好地工作,只是表明已找到了它。
@echo off
setlocal enabledelayedexpansion
echo "Hotfix & Updates list."
Echo.
(for /f %%a in ('type c:\KB-list.txt') do (
echo "Searching For KB%%a"
Echo.
systeminfo | findstr KB%%a
))
for /f %%i in ('type C:\KB-list.txt') do (
echo "Uninstalling KB%%i"
wusa /uninstall /kb:%%i /quiet /norestart
)
echo "Uninstall(s) Complete."
echo.
echo "Done"
echo.
echo "Rebooting…"
echo.
shutdown /r
再次感谢!
答案 0 :(得分:2)
多次运行systeminfo效率很低。
使用findstr / g选项一次比较整个列表:
:: Q:\Test\2018\10\11\SO_52761793.cmd
@echo off
setlocal enabledelayedexpansion
set "Log=^>^> Logfile.log"
%Log% echo Hotfix and Updates list.
%Log% Echo(
for /f "tokens=2 delims=B" %%i in ('
systeminfo^|findstr /g:KB-list.txt'
) do (
echo [%date% %time%] Uninstalling KB%%i"
%Log% echo [%date% %time%] Uninstalling KB%%i"
wusa /uninstall /kb:%%i /quiet /norestart && (echo [%date% %time%] Done)||(echo [%date% %time%] failed)
)
( echo [!date! !time!] Uninstall(s^) Complete.
echo(
echo Done
echo(
echo Rebooting…
echo(
) %Log%
shutdown /r
编辑:精简变体而无需登录
:: Q:\Test\2018\10\11\SO_52761793.cmd
@echo off
setlocal enabledelayedexpansion
echo Hotfix and Updates list.
Echo(
for /f "tokens=2 delims=B" %%i in ('
systeminfo^|findstr /g:KB-list.txt'
) do (
echo Uninstalling KB%%i"
wusa /uninstall /kb:%%i /quiet /norestart && (echo Done)||(echo failed)
)
echo Uninstall(s) Complete.
echo(
echo Done
echo(
echo Rebooting…
echo(
shutdown /r