Pascal Scripting: ExecWithNativeSysDir

Prototype:

function ExecWithNativeSysDir(const Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ResultCode: Integer): Boolean;

Description:

Use this function instead of Exec to launch an executable located in the 64-bit System directory from a 32-bit installer.

This function avoids the problem that Exec in a 32-bit installer can only launch such an executable using the Sysnative alias, while that alias is not available to 64-bit applications. To achieve this, the function temporarily disables WOW64 file system redirection.

Remarks:

On 32-bit Windows or in a 64-bit installer, this function is just an alias for Exec.

Example:
var
  ResultCode: Integer;
begin
  if IsWin64 then begin
    { This starts 32-bit cmd.exe in a 32-bit installer, and 64-bit cmd.exe in a 64-bit installer }
    Exec(ExpandConstant('{cmd}'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode);
    { This starts 64-bit cmd.exe in both a 32-bit installer and a 64-bit installer }
    ExecWithNativeSysDir(ExpandConstant('{cmd}'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode);
    { WRONG: This would also start 64-bit cmd.exe in a 32-bit installer, but it would use the Sysnative alias, which 64-bit cmd.exe cannot access } 
    // Exec(ApplyPathRedirRulesForCurrentProcess(True, ExpandConstant('{cmd}')), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode);
  end;