Inno Setup 始终在 Pascal Script 代码中以 32 位模式启动 PowerShell

Al *_*aba 2 windows installation inno-setup wow64 pascalscript

我想在我的Inno Setup步骤中使用PowerShell(64位版本)ssPostInstall,但它总是打开32位PowerShell。

正如您在我的脚本中看到的,我的 Inno Setup 配置为 64 位应用程序。当我开始安装时,我可以在任务管理器中看到它正在作为 32 位应用程序运行

在此输入图像描述

此外,将打开的 PowerShell 也处于 32 位模式。

在此输入图像描述

这是我的 Inno Stup 脚本:

[Setup]
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
PrivilegesRequired=admin

[Code]
Procedure CurStepChanged(CurrentStep:TSetupStep);
var
  i, ResultCode, ErrorCode: Integer;
  findRec: TFindRec;
  isInstallationCmdSuccessful: Boolean;  
  folderNameOfUpdateIni: String;
  ReturnCode: Boolean;

begin  
  if CurrentStep = ssPostInstall then begin
      Log('Starting post install steps, calling install.ps1');
      ReturnCode := ShellExec('open', ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
      if (ReturnCode = True) then
        Log('post install returned true')
      else
        Log('post install returned false');


      Log('Starting post install steps, calling install.ps1');
      ReturnCode := ShellExec('open', ExpandConstant('{syswow64}\WindowsPowerShell\v1.0\powershell.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
      if (ReturnCode = True) then
        Log('post install returned true')
      else
        Log('post install returned false');
  end;
end;
Run Code Online (Sandbox Code Playgroud)

如何强制 Inno Setup 打开 64 位 PowerShell?

Mar*_*ryl 5

如果要允许 Pascal Script 代码函数使用 64 位System32文件,请使用EnableFsRedirectionfunction禁用WOW64 文件系统重定向

而且你也不能使用ShellExec,你需要使用Execfunction来代替。

OldState := EnableFsRedirection(False);
try
  ReturnCode :=
    Exec('powershell.exe', '', '', SW_SHOWNORMAL, ewWaitUntilTerminated,
         ErrorCode);
finally
  EnableFsRedirection(OldState);
end;
Run Code Online (Sandbox Code Playgroud)

顺便说一句,ArchitecturesInstallIn64BitMode不会/无法使 Inno Setup 作为 64 位应用程序运行。无论如何,Inno Setup 都是 32 位应用程序。