RightFax Universal Uninstaller

From psadt | Evergreen Application Management
Jump to navigation Jump to search

About

RightFax.jpg


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 | psadt.com

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


#region Function
Function WriteLog
    {
	Param ([string]$logstring)
	Add-content $appLogFile -value $logstring
	Write-Host $logstring
    }
#endregion


# Remove previous versions if exist

# EXE Uninstall
If (Test-Path "$appPath\Setup.exe")
	{
	$OldVersion = (Get-Item "$appPath\Setup.exe").VersionInfo.FileVersion
	WriteLog "Uninstalling RightFax $OldVersion"
	$Parms = "/remove /unattended=true /allowShutdown=false /norestart"
	Stop-Process -Name FAXCTRL -Force | Out-Null
	Stop-Process -Name fuw32 -Force | Out-Null
	Write-Log -Message "Executing $appPath\Setup.exe $Parms"
	Start-Process "$appPath\Setup.exe" -ArgumentList $Parms -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)
			{
			[string]$pkgGUID = $($app.IdentifyingNumber)
			[string]$oldVersion = $($app.Version)
			[string]$Parms = "/X $pkgGUID RUNBYRIGHTFAXSETUP=2 REBOOT=R /q /l*v `"$appLogPath\Captaris RightFax $oldVersion Uninstall.log`""
			WriteLog "Uninstalling RightFax $oldVersion"
			WriteLog "MsiExec /x $pkGUID $Parms"
			Start-Process -FilePath MsiExec.exe -ArgumentList $Parms -Wait -PassThru -NoNewWindow -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
			}
		}
	}