I am trying to package a program with an InstallShield installer. The installer is a .exe file. Unfortunately, I am writing my own chocolateyUninstall.ps1
, as Chocolatey's auto-uninstaller is failing to detect and uninstall the program by itself. To this end I am trying to use the Uninstall-ChocolateyPackage cmdlet like this:
$ErrorActionPreference = 'Stop'
$packageArgs = @{
packageName = $env:ChocolateyPackageName
softwareName = 'TRACE32*'
fileType = 'EXE'
silentArgs = '/s'
validExitCodes = @(0)
}
[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName']
if ($key.Count -eq 1) {
$key | % {
$packageArgs['file'] = "$($_.UninstallString)".Trim()
Uninstall-ChocolateyPackage @packageArgs
}
}
When calling Uninstall-ChocolateyPackage
the packageArgs
hashmap contains the following values:
$packageArgs['packageName'] = trace32
SpackageArgs['softwareName'] = TRACE32*
$packageArgs['file'] = "C:\Program Files (x86)\InstallShield Installation Information\{A31FFDB6-5922-4D9E-ADB1-285E5D999D70}\setup.exe" -runfromtemp -l0x0409 -removeonly
$packageArgs['fileType'] = EXE
$packageArgs['silentArgs'] = /s
But at this point chocolateyUninstall.ps1
crashes stating that there are "illegal characters in the path" ... However, when I copy the contents of $packageArgs['file']
to an elevated command line (CMD or PowerShell), paste it and run it the uninstallation of the program proceeds normally and successfully.
I could not find any report of such an issue with Google. Has anyone ever encountered a problem like this? And, if yes, what was the root cause and how did you solve it? I would like for Chocolatey-UninstallPackage
to call the uninstallation command registered in the Windows Registry properly and finish successfully.
I am still using Chocolatey 1.3.1 if that is relevant.
Thanks in advance for your input!
Just to be clear, nothing is 'crashing'. An exception is being thrown, which is what is intended to happen.
The problem you have is that your hashtable is wrong. The $packageArgs['file']
doesn't contain a filename. It contains a filename AND args. You need to split that up into the filename, and the args left need to go into $packageArgs['silentArgs']
like this:
$packageArgs['packageName'] = trace32
SpackageArgs['softwareName'] = TRACE32*
$packageArgs['file'] = "C:\Program Files (x86)\InstallShield Installation Information\{A31FFDB6-5922-4D9E-ADB1-285E5D999D70}\setup.exe"
$packageArgs['fileType'] = EXE
$packageArgs['silentArgs'] = "-runfromtemp -l0x0409 -removeonly"
Note that I'm assuming those $packageArgs['silentArgs']
do actually uninstall it silently.
I am still using Chocolatey 1.3.1 if that is relevant.
That is an old and unsupported version of Chocolatey CLI that was released over a year ago.