Al Phaba
Al Phaba

Reputation: 6775

Inno Setup always starts PowerShell in 32-bit mode in Pascal Script code

I want to use PowerShell (64-bit version) in the ssPostInstall step of my Inno Setup, but it always opens a 32-bit PowerShell.

As you can see in my script my Inno Setup is configured as 64-bit application. When I start the setup I can see in the Task Manager that it is running as a 32-bit application

enter image description here

Also the PowerShell which will be opened, is in 32 bit-mode.

enter image description here

Here is my Inno Stup script:

[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;

How can I force Inno Setup to open a 64-bit PowerShell?

Upvotes: 2

Views: 1086

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202514

If you want to allow Pascal Script code functions to use 64-bit System32 files, use EnableFsRedirection function to disable WOW64 file system redirection.

And you also cannot use ShellExec, you need to use Exec function instead.

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

Btw, ArchitecturesInstallIn64BitMode does not/cannot make Inno Setup run as 64-bit application. Inno Setup is 32-bit application, no matter what.

Upvotes: 5

Related Questions