Crew Two

RightFax Universal Uninstaller

About

RightFax securely sends and receives documents from a variety of sources via the cloud or telephone connections.

It has to be one of the worst applications I’ve worked with as an automator. Every version that is released has a new type of installer that works differently to previous versions. It throws random errors, but not consistently. It fails to quit, but not consistently. It must be uninstalled using the executable – but, you guessed it, not consistently (the latest version can ONLY be uninstalled with the MSI, which complains if not called from the Setup.exe, and Setup.exe has no uninstall option when run manually 🙂 )

Bring on the challenge!

Uninstall.ps1

# This script performs the installation or uninstallation of an application(s).
# Created 14/08/2019 | cru2.io

# Variables
[string]$CurrentPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
[string]$appPath = "${env:ProgramFiles(x86)}\RightFax\Setup"
[string]$appLogPath = "$env:ProgramData\Software"
If (!(Test-Path $appLogPath))
	{New-Item -ItemType Directory $appLogPath -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null}


Start-Transcript -Path "$appLogPath\RightFax Universal Uninstaller.log" -Append

# Remove previous versions if exist

# EXE Uninstall
If (Test-Path "$appPath\Setup.exe")
	{
	$OldVersion = (Get-Item "$appPath\Setup.exe").VersionInfo.FileVersion
	Write-Host "Uninstalling RightFax $OldVersion"
	Stop-Process -Name FAXCTRL -Force | Out-Null
	Stop-Process -Name fuw32 -Force | Out-Null
	Start-Process "$appPath\Setup.exe" -ArgumentList "/remove /unattended=true /allowShutdown=false /norestart" -PassThru -NoNewWindow -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
	}

# Close error | Does not occur consistently hence the time loop to check for it
$TimeStart = Get-Date
$TimeEnd = $timeStart.addminutes(1)
Do {
	$TimeNow = Get-Date
	If ($TimeNow -ge $TimeEnd){}
	Else
		{
		$wshell = New-Object -ComObject wscript.shell;
		$wshell.AppActivate('RightFax Product Suite Setup Error')
		Sleep 1
		$wshell.SendKeys("{ENTER}")
		}
	Sleep 5
}
Until ($TimeNow -ge $TimeEnd)


# MSI Uninstall
If (Test-Path "$appPath\Setup.exe")
	{
	$UninstMSI = Get-WmiObject -Class win32_product | where { $_.Name -like "*RightFax*"}
	If ($UninstMSI -ne $null)
		{
		ForEach ($app in $UninstMSI)
			{
			Write-Host "Uninstalling RightFax $($app.Version)"
			Start-Process -FilePath MsiExec.exe -ArgumentList "/X $($app.IdentifyingNumber) RUNBYRIGHTFAXSETUP=2 REBOOT=R /q /l*v `"$appLogPath\Captaris RightFax $($app.Version) Uninstall.log`"" -Wait -PassThru -NoNewWindow -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
			}
		}
	}

Stop-Transcript | Out-Null

About: nick