Search code examples
powershell7zip

SFX installer fails to run powershell script after powershell window is opened


I am creating an 7zip sfx installer in latest Windows 10 which is expected to run a powershell script. when extraction is done, the powershell window is shown up but quickly closed without executing the script.

Any help is much appreciated!

I have tried to sign the script file and the installer.exe itself with self signed certificate, but no luck.

I have changed the Powershell ExecutionPolicy to Unrestricted for all scopes for troubleshooting, but no luck either

I use process monitor in sysinternals to capture the powershell.exe behavor, and found powershell starts to exit thread after reading and writing c:\Users\xxx\AppData\Local\Microsoft\Windows\PowerShell\StartupProfileData-Interactive

Here is my config.txt for 7zip sfx:

;!@Install@!UTF-8!
Title="Cloud API"
BeginPrompt="Do you want to install Cloud API?"
RunProgram="powershell.exe -NoExit –NoProfile -ExecutionPolicy Bypass -File %%T\\cloud_api\\installer.PS1"
Directory="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\"
;!@InstallEnd@!

I am zipping the files in python by:

..\\7zr a -sfx7zSD.sfx cloud-api.7z .\\cloud-api -r -y

I am expecting the installer.PS1 getting executed after unzipping, but only powershell.exe is run and exit quickly without running the script at all.


Solution

  • A first step to troubleshooting this problem would be to declare the full path of the .ps1 script in your 7zip config. This will ensure you are calling the script you intend to launch.