2

我想在我的 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;

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

4

1 回答 1

4

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

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

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

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

于 2018-12-07T10:22:20.200 回答