Invalid character in path? Get-InstalledApplication - UninstallString

How come my code fail??

[Pre-Installation] :: @{InstallSource=; UninstallString="C:\Program Files\ShareX\unins000.exe"; UninstallSubkey=82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC_is1; InstallLocation=C:\Program Files\ShareX\; ProductCode=; Is64BitApplication=True; Publisher=ShareX Team; InstallDate=20200528; DisplayVersion=13.1.0; DisplayName=ShareX}
		$ShareX = Get-InstalledApplication -Name "ShareX"
		Write-Log -Message "$($ShareX.UninstallString)" -Source "$installPhase" -LogType 'CMTrace' -Severity '3'
		if ($ShareX) {
			## UNINSTALL ShareX Team ShareX 13.1.0
			Write-Log -Message "$ShareX" -Source "$installPhase" -LogType 'CMTrace' -Severity '1'
			Execute-Process -Path "$($ShareX.UninstallString)" -Parameters '/S' -WindowStyle 'Hidden'
		}

[Pre-Installation] :: Function failed, setting exit code to [60002].
Error Record:

Message : Exception calling “IsPathRooted” with “1” argument(s): “Ugyldige tegn i stien.”
InnerException : System.ArgumentException: Ugyldige tegn i stien.
ved System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
ved System.IO.Path.IsPathRooted(String path)
ved CallSite.Target(Closure , CallSite , Type , Object )

FullyQualifiedErrorId : ArgumentException
ScriptStackTrace : at Execute-Process, W:\ShareX\13.1.0\DeployFiles\AppDeployToolkit\AppDeployToolkitMain.ps1: line 2813
at , W:\ShareX\13.1.0\DeployFiles\Deploy-Application.ps1: line 131
at , : line 1
at , : line 1

PositionMessage : At W:\ShareX\13.1.0\DeployFiles\AppDeployToolkit\AppDeployToolkitMain.ps1:2813 char:8
+ … If (([IO.Path]::IsPathRooted($Path)) -and ([IO.Path]::HasExte …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error Inner Exception(s):

Message : Ugyldige tegn i stien.
InnerException :

it fail in the

Execute-Process -Path “$($ShareX.UninstallString)” -Parameters ‘/S’ -WindowStyle ‘Hidden’

What is value of $ShareX.UninstallString

I think it was
C:\Program Files\ShareX\unins000.exe
But think it a general issue. Cause if i pasta above path in directly it works

Think it a general issue with non msi installer exe

[Pre-Installation] :: @{InstallSource=; UninstallString=“C:\Program Files\ShareX\unins000.exe”; UninstallSubkey=82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC_is1; InstallLocation=C:\Program Files\ShareX; ProductCode=; Is64BitApplication=True; Publisher=ShareX Team; InstallDate=20200528; DisplayVersion=13.1.0; DisplayName=ShareX}

Try this

Execute-Process -Path "`"C:\Program Files\ShareX\unins000.exe -Parameters ‘/S’ -WindowStyle ‘Hidden’

Note : between .exe and -Parameters `""

Because there is a space in C:\Program Files\ShareX\unins000.exe

The raw path will work but want to use the $ShareX.UninstallString variable so i need to put some “” around it

Try this

Execute-Process -Path "`"$($ShareX.UninstallString)`"" -Parameters ‘/S’ -WindowStyle ‘Hidden’

Because there is an space in C:\Program Files\ShareX\unins000.exe
1 Like