Uninstall exe if exists before installing newer version

Hi Guys

Im hoping you can point me in the right direction I need to uninstall keepass that was installed as a EXE before upgrading with the newer MSI as it will not just update the older version it will install the newer one and keep the older one. . The problem I have is not all the devices have the older Keepass installed but a lot do. If I put the below command in the script and the user has the older version installed it works as ecpexted but if its not installed it errors out.

Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt

	Show-InstallationWelcome -CloseApps 'Keepass Password Safe' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt

	## Show Progress Message (with the default message)

	## <Perform Pre-Installation tasks here>
       Execute-Process -Path 'C:\Program Files\KeePass Password Safe 2\unins000.exe' -Parameters '/SILENT'

How about something like this:

If (Test-Path 'C:\Program Files\KeePass Password Safe 2\unins000.exe') {
	Write-Log "Found old unins000.exe and using it."
	Execute-Process -Path 'C:\Program Files\KeePass Password Safe 2\unins000.exe' -Parameters '/SILENT'
	#TO DO: Handle uninstall failure, add logging parameter to unins000.exe if possible.
} Else {
	Write-Log "old unins000.exe NOT found. Assuming all is well to proceed"
1 Like

Worked perfectly! Thank you

Your far from “annoying” LOL