Reputation: 3076
I am having a scenario that if an application is already installed, then first uninstall the older version, then install new version.
I have written following piece of code in a batch file using 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
I am facing an issue that when execution goes to if (exist)
block, lets assume application is already installed, then it goes inside if
block and start uninstall the application and runs it asynchronously and start executing the next line (installing the new version) and it cause a problem that "another installation is already in progress".
All I want that once it goes for uninstalling the application, it should wait until it is finished, then only go to next line for execution (installing newer version).
Upvotes: 0
Views: 1471
Reputation: 18757
You need to use the third parameter of WSHShell.Run()
, set it to true to wait for completion of the command.
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
Upvotes: 2