Pascal Scripting: EnableFsRedirection

Prototype:

function EnableFsRedirection(const Enable: Boolean): Boolean;

Description:

Controls whether built-in support functions that access files disable WOW64 file system redirection (with some exceptions). Specify True in the Enable parameter to leave redirection enabled when those functions are called; specify False to disable it. Returns the previous redirection state (True if redirection was enabled).

If False is passed in the Enable parameter and the user isn't running a supported 64-bit version of Windows, an exception will be raised. To avoid the exception, call IsWin64 first.

Remarks:

After you've performed the operation that required changing the redirection state, be sure to restore the previous state. Always use a try..finally language construct to ensure that the previous state is restored even if an exception occurs. See below for an example.

By default, file system redirection is enabled in 32-bit install mode, and disabled in 64-bit install mode.

This function has no effect on calls to functions in external DLLs. When invoking external functions, file system redirection is always left enabled.

It is legal to call this function with True in the Enable parameter if the user isn't running a 64-bit version of Windows. In such a case, the call has no effect.

Example:

The following example demonstrates how to launch an executable located in the 64-bit System directory. (Note: In 64-bit install mode, it isn't necessary to call EnableFsRedirection because file system redirection is already disabled by default.)

var
  OldState: Boolean;
  ResultCode: Integer;
begin
  // First verify that the user is running a supported 64-bit version
  // of Windows, because calling EnableFsRedirection(False) will
  // raise an exception otherwise.
  if IsWin64 then
  begin
    // Turn off redirection, so that cmd.exe from the 64-bit System
    // directory is launched.
    OldState := EnableFsRedirection(False);
    try
      Exec(ExpandConstant('{cmd}'), '', '', SW_SHOW,
        ewWaitUntilTerminated, ResultCode);
    finally
      // Restore the previous redirection state.
      EnableFsRedirection(OldState);
    end;
  end;
end;