打开 powershell window 后,SFX 安装程序无法 运行 powershell 脚本

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

我正在最新的 Windows 10 中创建一个 7zip sfx 安装程序,预计 运行 一个 powershell 脚本。提取完成后,powershell window 会显示,但会在不执行脚本的情况下快速关闭。

非常感谢任何帮助!

我尝试使用自签名证书对脚本文件和 installer.exe 本身进行签名,但没有成功。

我已将所有范围的 Powershell ExecutionPolicy 更改为 Unrestricted 以进行故障排除,但也不走运

我在sysinternals中使用process monitor来捕捉powershell.exe行为,发现powershell读写c:\Users\xxx\AppData\Local\Microsoft\Windows\PowerShell\StartupProfileData-Interactive

后开始退出线程

这是我的 config.txt 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@!

我正在通过以下方式压缩 python 中的文件:

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

我期待安装程序。PS1 在解压缩后执行,但只有 powershell.exe 是 运行 并在根本没有 运行 脚本的情况下快速退出。

解决此问题的第一步是在您的 7zip 配置中声明 .ps1 脚本的完整路径。这将确保您正在调用您打算启动的脚本。