脚本不等待语句完成并开始执行下一行
Script does not wait for statement to finish and starts executing next line
我有一个场景,如果一个应用程序已经安装,那么先卸载旧版本,然后安装新版本。
我使用 VBScript 在批处理文件中编写了以下代码:
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")
path="C:\Program Files\MySetup\My App 3.5" 'path to folder
exists = fso.FolderExists(path)
if (exists) then
WshShell.Run "msiexec /qb /x {3D5D4357-217C-49BA-A8E8-00907D631F05} "
end if
WshShell.Run "msiexec /qb /i C:\Build\" & msiFileName
我遇到一个问题,当执行到 if (exist)
块时,假设应用程序已经安装,然后它进入 if
块并开始卸载应用程序并异步运行它并开始执行下一行(安装新版本)并导致 "another installation is already in progress".
问题
我只希望一旦卸载应用程序,它应该等到它完成,然后才转到下一行执行(安装更新版本)。
需要使用WSHShell.Run()
的第三个参数,设置为true等待命令完成
if (exists) then
WshShell.Run "msiexec /qb /x {3D5D4357-217C-49BA-A8E8-00907D631F05} " ,0,true
end if
WshShell.Run "msiexec /qb /i C:\Build\" & msiFileName,0,true
我有一个场景,如果一个应用程序已经安装,那么先卸载旧版本,然后安装新版本。
我使用 VBScript 在批处理文件中编写了以下代码:
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")
path="C:\Program Files\MySetup\My App 3.5" 'path to folder
exists = fso.FolderExists(path)
if (exists) then
WshShell.Run "msiexec /qb /x {3D5D4357-217C-49BA-A8E8-00907D631F05} "
end if
WshShell.Run "msiexec /qb /i C:\Build\" & msiFileName
我遇到一个问题,当执行到 if (exist)
块时,假设应用程序已经安装,然后它进入 if
块并开始卸载应用程序并异步运行它并开始执行下一行(安装新版本)并导致 "another installation is already in progress".
我只希望一旦卸载应用程序,它应该等到它完成,然后才转到下一行执行(安装更新版本)。
需要使用WSHShell.Run()
的第三个参数,设置为true等待命令完成
if (exists) then
WshShell.Run "msiexec /qb /x {3D5D4357-217C-49BA-A8E8-00907D631F05} " ,0,true
end if
WshShell.Run "msiexec /qb /i C:\Build\" & msiFileName,0,true