sasha
Posts: 67
Joined: Fri Oct 20, 2023 8:37 pm

An issue with running PowerShell scripts

Hello! Our (un)installer runs a few Powershell scripts. They all are running from the temp folder (as specified in the Powershell execution options).

Unfortunately, on some systems, the invocation of the scrip generates the following error:

> MSI (c) (44:90) [18:40:33:647]: Invoking remote custom action. DLL: C:\Users\S12DE~1.RAM\AppData\Local\Temp\MSI462.tmp, Entrypoint: RunPowerShellScript
[INFO] PowerShell script preferred invocation folder:
Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 574
--> PowerShell Script Execution log:
ERROR: An object at the specified path C:\Users\S12DE~1.RAM does not exist.

MSI (c) (44!08) [18:41:01:987]: PROPERTY CHANGE: Adding POWERSHELL_EXECUTION_LOG property. Its value is 'ERROR: An object at the specified path C:\Users\S12DE~1.RAM does not exist.'.
CustomAction XXXX returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)

Searching online results in a few hits:
https://stackoverflow.com/questions/107 ... powershell
https://stackoverflow.com/questions/415 ... -not-exist

I wonder if there is a possibility of the Advanced Installer changing/fixing how the temp file location is determined? So the PS scripts can run without the errors?

Thanks!
Catalin
Posts: 7492
Joined: Wed Jun 13, 2018 7:49 am

Re: An issue with running PowerShell scripts

Hello Sasha,

From what I currently understand, this issue is machine related.
I wonder if there is a possibility of the Advanced Installer changing/fixing how the temp file location is determined? So the PS scripts can run without the errors?
I'm afraid that I do not quite understand this question.

In order for me to have a better view on this issue, I would need to reproduce this on my end so I can further investigate it.

For instance, are you able to reproduce this issue on your end? If so, have you managed to find what option is the "culprit"?

If that's the case, please forward me a sample AIP file (it can be empty, only containing the script) that reproduces this by email at support at advancedinstaller dot com together with a test-case so I can further investigate this.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sasha
Posts: 67
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue with running PowerShell scripts

Thanks for the reply, Catalin.
The issue does seem to be machine-specific. I cannot reproduce this at-will. The same MSI will work fine elsewhere, but fail on a 'bad' system.
The 'run from' is selected to be the temporary folder in the AI Powershell script options.

The links I included possible explanation on what happens with the temp folder location and Powershell. Basically, using the $env:temp is unreliable. I don't know if internally AI is using that or not.

The 'bad' systems seem to be such where the %userprofile% ends up being in the 'short path' form. That includes accounts in this form: first.last or "first last".

So, in short, providing an .aip is probably not useful. I suspect any .aip that includes running an inline Powershell script that run on a 'bad' system will fail. How to get a system into the 'bad' state (if having a 'funky' account name is not enough), I don't know. Again, if AI is relying on $env:temp, that's the problem. If AI doesn't rely on that, then I don't know what a solution could be.

Thanks!
Catalin
Posts: 7492
Joined: Wed Jun 13, 2018 7:49 am

Re: An issue with running PowerShell scripts

Hello,

Thank you for your followup on this!

If you manage to find the culprit here, please let me know and I will gladly test this on our end.

Regarding the $env:temp, please note that we do not use it, so I do not think that's what's causing this.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sasha
Posts: 67
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue with running PowerShell scripts

Hi Catalin. The time has come to revisit this issue :)

To reiterate, the installer fails to execute a powershell script when a user's temp folder environment variable is set in the short form, i,e. like this: c:\users\dom~1\tmp
The script is marked to be run from a temp folder in the .aip file.

Another tidbit that I was able to determine is that using the /qn argument on the command line results in a successful installation.

We are building an .exe installer.

I suppose a workaround is to execute the script from the product folder, but we don't need it present after the installation and I'm not sure how to mark it to be deleted in this case.

Perhaps a fix for this can be combined with the tampering fix :)

Thanks!
sasha
Posts: 67
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue with running PowerShell scripts

An update.
At this point I don't think this is a problem in the Advanced Installer.
Our PowerShell script CA executes another script, which is located in a folder like this: C:\Users\user1~1.nam\AppData\Local\Temp\{77344E7F-E3D2-4990-8266-1A782F66B7B4}\installscripts.ps1
The path was passed in from the CA using the built-in AI temporary script's location (via a [Property] mechanism. The path to the script is enclosed in double quotes.

When this path includes both short name *and* the curly braces, it appears that the PowerShell startup code simply strips the part that starts with the curly brace.
So, as a result, our script fails to launch another script (via Start-Process -File).

Now I'm going to spend some time Googling...
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: An issue with running PowerShell scripts

Hello Sasha,

Sorry for the delayed reply on this.

If possible, could you please create a sample project that reproduces this and forward it to me (it could be either here or by e-mail at support at advancedinstaller dot com)?

And I will also try to see if there is a solution.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”