Pascal Scripting: ApplyPathRedirRules

Prototype:

function ApplyPathRedirRules(const Path64Bit: Boolean; const Path: String; const TargetProcess: TPathRedirTargetProcess): String;

Description:

Applies system path redirection to the specified path and returns the rewritten path.

Path64Bit specifies the current bitness of PathTrue for 64-bit, or False for 32-bit. TargetProcess specifies the bitness of the process where the rewritten path will ultimately be accessed. In the System Path Redirection topic's table, these are the "entry bitness" and "target process bitness", respectively.

Before rewriting, the path is expanded using ExpandFileName and converted to an extended-length path (also known as a super path).

Path expansion and conversion to extended-length path always occurs, even if nothing is rewritten.

Remarks:

On systems running 32-bit Windows, Path64Bit must be False, otherwise an exception will be raised.

TPathRedirTargetProcess is an enumerated type, defined as:

TPathRedirTargetProcess = (tpCurrent, tpNativeBit, tp32Bit, tp32BitPreferSystem32);

ValueTarget process bitness
tpCurrent64-bit in 64-bit Setup/Uninstall, or 32-bit in 32-bit Setup/Uninstall
tpNativeBit64-bit when running on 64-bit Windows, or 32-bit on 32-bit Windows
tp32Bit32-bit
tp32BitPreferSystem3232-bit, with System32 instead of SysWOW64 in the resulting path (see System Path Redirection for details)
Example:
var
  InPath, OutPath: String;
begin
  InPath := ExpandConstant('{sys}\MyLibrary.dll');
  Log(InPath);
  // Typically logs: C:\Windows\System32\MyLibrary.dll

  // Convert 64-bit path to path accessible in current process
  if IsWin64 then
  begin
    OutPath := ApplyPathRedirRules(True, InPath, tpCurrent);
    Log(OutPath);
    // In 32-bit Setup, logs: \\?\C:\Windows\Sysnative\MyLibrary.dll
    // In 64-bit Setup, logs: \\?\C:\Windows\System32\MyLibrary.dll
  end;

  // Convert 32-bit path to path accessible in current process
  OutPath := ApplyPathRedirRules(False, InPath, tpCurrent);
  Log(OutPath);
  // In 32-bit Setup, logs: \\?\C:\Windows\SysWOW64\MyLibrary.dll
  // In 64-bit Setup, logs: \\?\C:\Windows\SysWOW64\MyLibrary.dll
end;
See also:

ApplyPathRedirRulesForCurrentProcess
PathConvertSuperToNormal