从 {app} 执行的 PowerShell 脚本在 Inno Setup 中失败,而从 {tmp} 执行的 PowerShell 脚本正在运行

PowerShell script execution from {app} failing in Inno Setup, while an execution from {tmp} is working

我的安装程序 运行 是一个 PowerShell 脚本,用于在安装时创建证书。在 [Files] 部分,我复制了两个 PowerShell 脚本(一个用于安装,一个用于卸载):

[Files]
Source: "MyApp\Certs.ps1"; DestDir: "{tmp}\Neogen"; Flags: ignoreversion; \
    Permissions: everyone-full              
Source: "MyApp\UninstallCerts.ps1"; DestDir: "{app}"; Flags: ignoreversion; \
    Permissions: everyone-full

安装证书的脚本使用临时目录,卸载脚本使用 app 目录,通常将其放入 C:\Program Files (x86)\MyApp 文件夹中。我可以确认卸载脚本已放入正确的文件夹中。

当我卸载应用程序时,证书并没有被卸载。脚本如下所示:

Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.FriendlyName -match 'MyCert' } | Remove-Item
Get-ChildItem Cert:\LocalMachine\Root | Where-Object { $_.FriendlyName -match 'MyCert' } | Remove-Item

如果我打开具有管理员权限的 PowerShell window 并转到 C:\Program Files (x86)\MyApp 文件夹以手动 运行 脚本,脚本确实有效 – 证书被删除。它只是 运行从添加/删除程序 window 卸载过程失败。

我在 Inno Setup 中的卸载代码如下所示:

[UninstallRun]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File """"{app}\UninstallCerts.ps1 ""{app}"" """""; \
  Flags: runhidden; RunOnceId: "MyAppId"

在卸载时尝试 运行 这个 PowerShell 脚本时我错过了什么?

以下是证书创建脚本(运行 成功)的执行语法:

[Run]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File """"{tmp}\Certs.ps1 ""{commonappdata}"" """""; \
   Flags: runhidden

问题可能是 {app} 包含空格(Program Files?),而 {tmp} 不包含空格。您的语法无法正确处理带空格的路径。

这是correct syntax:

[Run]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\Certs.ps1"" ""{commonappdata}""";\ 
  Flags: runhidden

[UninstallRun]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File ""{app}\UninstallCerts.ps1"" ""{app}"""; \
  Flags: runhidden; RunOnceId: "MyAppId"

你的语法中的 """"" 是 noop。它将 "" 传递给 PowerShell,PowerShell 将其视为无。