I’m using the Uninstall-ADTApplication in the pre-install section of the PSADT because I want to remove the older applications first.
The problem is that it seems that Uninstall-ADTApplication does not wait for the uninstaller.exe to finish. So the uninstaller.exe runs, the installer.exe of the new application runs and finishes before the uninstaller.exe of the old version finishes. This results that the new version is also partly uninstalled.
Is there any way to overcome this ? I could use a Start-Sleep, but actually I want to avoid that because I do not know exactly how long the uninstall takes. Of course I could be safe with 60 seconds, but then again, I do not think this is the correct way.
You’ll probably find that Uninstall-ADTApplication is waiting, it’s that the Start-ADTProcess code is not though. There are installers out there that open a process and expand stuff to temp, then fork out to a second process, ending the first. This is something Start-ADTProcess can’t handle because it’s something the process code in C# can’t handle.
In our upcoming 4.1.0 release, there’s a -WaitForChildProcesses parameter that can help with this as it will wait until that forked process is finished. A release candidate for this is due on Monday.
In the mean time, to test the logic, can you run the uninstall command for the application manually (i.e. call Get-ADTApplication so you can see the QuietUninstallString, then run it via Start-ADTProcess directly in a console). If Start-ADTProcess returns you to the console before the uninstall has finished, that’ll demonstrate my point.
@mjr4077au Thanks for the clarification. Before using the Uninstall-ADTApplication I had the code below (wasn’t aware of the Uninstall-Application function ) and used Start-ADTProcess to run the uninstaller. I already figured out that the Start-ADTProcess didn’t wait either, so I started using Start-Process with the -Wait parameter, which works.
## <Perform Pre-Installation tasks here>
# Check if old Notepad++ version exists regardless of the installation path, if so, uninstall the old version
# Define application to be uninstalled. This is the DisplayName also shown in appwiz.cpl
$targetApp = "Notepad++ (64-bit x64)"
# Search for 32 and 64bit registry information
$paths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$app = Get-ItemProperty -Path $paths | Where-Object {
$_.DisplayName -eq $targetApp -and $_.UninstallString -and ($_.UninstallString -notlike "*msiexec*")
}
if ($app) {
#Write-Host "Uninstalling: $($app.DisplayName)"
Start-Process -FilePath "$($app.UninstallString)" -ArgumentList "/S" -Wait
#Start-ADTProcess -FilePath "$($app.UninstallString.Trim('"'))" -ArgumentList '/S' --> Does not work correctly because it does not wait for the uninstaller to finish because no Wait parameter exists
}
#else {
# Write-Host "App not found: $targetApp"
#}
If Start-Process -Wait works, then Start-ADTProcess -WaitForChildProcesses will work also. The 4.1.0 release can’t come soon enough! Keep an eye out for a release candidate on Monday.