我的批处理文件有问题。
@echo off
:START
echo Are you ready?
SET logpath=xxx
:COPY
pause
xxx
:FIRST
for /f %%g IN (hostnames.txt) do (
::xcopy "xxx*.*" \\%%g\c$\temp\ /f /s /y /i
echo PC %%g >> %logpath%\xxx
echo %%g > appname.txt
psexec -h \\%%g cmd /c msiexec /i xxx
IF '%ERRORLEVEL%'=='0' (
echo xxx Success! >> %logpath%\xxx.txt
) else (
echo xxx Error is %ERRORLEVEL%. >> %logpath%\xxx.txt
)
psexec -h \\%%g cmd /c msiexec /i xxx
IF '%ERRORLEVEL%'=='0' (
echo xxx Success! >> %logpath%\xxx.txt
) else (
echo xxx Error is %ERRORLEVEL%. >> %logpath%\xxx.txt
)
:SECOND
psexec -h \\%%g cmd /c MsiExec.exe /I{xxx} /passive /norestart
IF '%ERRORLEVEL%'=='0' (
echo test {...-xxx} uninstalled! >> %logpath%\xxx.txt
goto THIRD
)
psexec -h \\%%g cmd /c msiexec /x "{xxx}" /passive /norestart
IF '%ERRORLEVEL%'=='0' (
echo Pierwszy {...-xxx} uninstalled! >> %logpath%\xxx.txt
goto THIRD
)
::Like 15 times uninstalling different apps
:THIRD
for /f %%g in (appname.txt) do taskkill -s %%g -im xxx.exe -f
for /f %%g in (appname.txt) do psexec -h \\%%g cmd /c msiexec /i xxx /passive /norestart
IF '%ERRORLEVEL%'=='0' (
echo xxx Success! >> %logpath%\xxx.txt
) else (
echo xxx. Error is %ERRORLEVEL%. >> %logpath%\xxx.txt
)
for /f %%g in (appname.txt) do psexec -h \\%%g cmd /c regedit /s xxx.reg
for /f %%g in (appname.txt) do psexec -h \\%%g cmd /c del c:\temp\xxx\*.* /f /s /q
echo. >> %logpath%\xxx.txt
echo. >> %logpath%\xxx.txt
)
首先,就像您在第三部分中看到的那样,我需要使用for /f %%g in (appname.txt) do psexec -h
而不是psexec -h
,因为psexec失败并且它“丢失”了主机名,这是我找到的唯一解决方法我自己。
第二件事(最重要的)是当批次运行到最后(到最后一个“)”时它停止。就像第一个循环for
已结束,它没有从文件hostnames.txt获取新的主机名
我很感激任何想法如何让它发挥作用