Forum Discussion
running an exe file from a sub folder of LocalAppData
I need to create a script that will run an .exe file to uninstall software on a users machine. I have created what I believe to be a simple code to do this, but as the .exe is in a sub folder of the users LOCALAPPDATA, my code only seems to go to the LOCALAPPDATA location and no further.
Can anyone assist in where it is failing?
This is what I have
Start-Process -FilePath $env:LocalAppData +"\**Redact**\update.exe --uninstall -s"
If my answer solved your issue, please mark it as solution to mark this topic as solved
5 Replies
- Did this help?
- BeddyTearCopper Contributor
If my answer solved your issue, please mark it as solution to mark this topic as solved
- LainRobertsonSilver Contributor
PowerShell isn't doing what you think it's doing.
You're expecting it to perform the concatenation of the two strings, then passing the resulting value in as the FilePath value. However, the first thing PowerShell does is parse the parameters, which means only the environment variable is passed in for FilePath, with the rest of the line being assumed to be parameters of some other description.
You should have been getting a helpful error though from PowerShell, as per the example below:
In the second example, you can see where I've used parenthesis to instruct PowerShell to do the concatenation of the string first, before passing the result of that concatenation in as the value for FilePath.
You will then need to split the executable command from the parameters as Harm_Veenstra has demonstrated above.
Cheers,
Lain
- You should use an argument list for this. (See https://lazyadmin.nl/powershell/start-process/) In your case, that should be something like this
Start-Process -FilePath$env:LocalAppData +"\**Redact**\update.exe -ArgumentList "--uninstall -s"