使用BAT文件记录成功卸载

时间:2017-04-03 14:53:19

标签: batch-file logging uninstall

我创建了一个BAT文件来卸载任何版本的Skype。它工作正常。我想将其设置为也检查事件查看器以查看它已成功卸载。我想知道是否有人做过这种性质的事情。到目前为止,这就是我所拥有的:

@echo off
echo Closing skype...
taskkill /F /IM Skype.exe
echo Removing previous versions...
wmic product where "Name like 'Skype%%'" call uninstall

新守则:

@ECHO off

IF EXSIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
ELSE IF EXSIST "C:\Program Files\Skype" GOTO INSTALLED
ELSE GOTO NOTINSTALLED

:Installed
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f

:NOTINSTALLED
EXIT

2 个答案:

答案 0 :(得分:0)

您可以查看%errorlevel%变量以获取上一个错误代码。

如果它为0,那么它有效!

if %errorlevel%==0 echo Uninstall successful

编辑:

新代码的更新,(您无法批量执行else if,只能单独使用它们)

@ECHO off
IF EXIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
IF EXIST "C:\Program Files\Skype" GOTO INSTALLED
EXIT

:INSTALLED
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f

答案 1 :(得分:0)

您可以尝试:

(
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
) > ".\uninstall_log.txt"

如果你想要控制台而不是使用它:

echo.
echo.
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
echo.
echo.
echo.
echo.Press any key to exit Skype uninstaller.
pause>nul
exit