Execute-process odd behavior

I updated to v3.6.9 to see if my 3.6.4 was the problem but it is not and errors the same on WIN10 and WIN7.

I pool registry to get 7-zip ininstall path set it to a variable for use later. echo the results and I get what I expect to see (a valid path) C:\Program Files (x86)\7-Zip\Uninstall.exe"

but when attempting to run this:
[String]$x86ver = Get-RegistryKey “HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip” -Value “UninstallString”
[String]$x64Ver = Get-RegistryKey “HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip” -Value “UninstallString”

    If ($x86ver -or $x64Ver){        
        Show-InstallationProgress -StatusMessage "Removing previous versions of $AppName."
        # uninstall the application
        If ($x86ver){
            write-host $x86Ver
            Execute-Process -Path $x86ver -Parameters ' /S'}
        If ($x64ver){
            write-host $x64Ver
            Execute-Process -Path $x64ver -Parameters ' /S'}
        }
    Remove-MSIApplications -Name '7-Zip'

I end up with the below errors.

[08-07-2017 12:18:19.072] [Pre-Installation] [Execute-Process] :: Function failed, setting exit code to [60002].
Error Record:

Message : Exception calling “IsPathRooted” with “1” argument(s): “Illegal characters in path.”
InnerException : System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.IsPathRooted(String path)
at CallSite.Target(Closure , CallSite , Type , Object )

FullyQualifiedErrorId : ArgumentException
ScriptStackTrace : at Execute-Process<Process>, C:\WINDOWS\Brunswick\AppDeployToolkit\AppDeployToolkitMain.ps1: line 2707
at <ScriptBlock>, C:\Temp\16.04\Deploy-7-Zip-16.04.ps1: line 153

PositionMessage : At C:\WINDOWS\Brunswick\AppDeployToolkit\AppDeployToolkitMain.ps1:2707 char:8
+ … If (([IO.Path]::IsPathRooted($Path)) -and ([IO.Path]::HasExte …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error Inner Exception(s):

Message : Illegal characters in path.
InnerException :

If I change things to use native cmds they work:

    [String$x86ver = Get-RegistryKey "HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" -Value "UninstallString"
    [String]$x64Ver = Get-RegistryKey "HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" -Value "UninstallString"
    
    If ($x86ver -or $x64Ver){        
        Show-InstallationProgress -StatusMessage "Removing previous versions of $AppName."
        # uninstall the application
        If ($x86ver){
            write-host $x86Ver
            Start-Process -FilePath $x86ver -ArgumentList ' /S' -Wait}
        If ($x64ver){
            write-host $x64Ver
            Start-Process -FilePath $x64ver -ArgumentList ' /S' -Wait}
        }
    
    Remove-MSIApplications -Name '7-Zip'

Anyone else experiencing this??

LOVE this tool

How about something like this?

$7ZIP = (Get-InstalledApplication -Name ‘7-zip’).UninstallString

If ($7ZIP) {
If ($7ZIP.StartsWith(“MsiExec.exe”)) {
Remove-MSIApplications -Name ‘7-zip’
}
Else {
Execute-Process -Path $7ZIP -Parameters ‘/S’
}
}

If you want to do it your way, remove the [String] at the beginning of your Get-RegistryKey variable declarations… But my way lets PSADT do the work of finding the correct uninstall string… Also, you may need to add a -eq $True to the StartsWith line like this:

If ($7ZIP) {
If ($7ZIP.StartsWith(“MsiExec.exe”) -eq $True) {
Remove-MSIApplications -Name ‘7-zip’
}
Else {
Execute-Process -Path $7ZIP -Parameters ‘/S’
}
}

I’ve had to do that in the past when the StartsWith was a number. It seems to work here without it, but you should test it both ways.

The problem is the quotations around the Uninstall String. I had a similar problem and resolved it like so.

$CCleanerUninstallEXE = (Get-InstalledApplication -Name ‘Ccleaner’).UninstallString.replace("`"","")
Execute-Process -Path $CCleanerUninstallEXE -Parameters “/S”

3 Likes