我目前有一个批处理脚本,该脚本使用powershell解压缩文件。
powershell Expand-Archive C:\File1\File22.zip -DestinationPath C:\File1\File2\
如果解压缩zip文件没有错误,我想运行以下命令:
echo set WshShell = WScript.CreateObject("WScript.Shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup( "Updating! Please wait... " ,10 ,"Update", 0)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
if %errorlevel%==1 (
echo You Clicked OK
) else (
echo The Message timed out.
)
del %tmp%\tmp.vbs
如何在代码中添加if
else
语句?
答案 0 :(得分:1)
您需要先执行powershell命令,然后检查并确保它以错误代码0(成功执行)退出。
powershell Expand-Archive C:\File1\File22.zip -DestinationPath C:\File1\File2\
If %ERRORLEVEL% == 0 (
echo set WshShell = WScript.CreateObject("WScript.Shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup( "Updating! Please wait... " ,10 ,"Update", 0))
>> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs
if ERRORLEVEL 1 (
echo You Clicked OK
) else (
echo The Message timed out.
)
del %tmp%\tmp.vbs
)