Pascal Scripting: EnableFsRedirection


function EnableFsRedirection(const Enable: Boolean): Boolean;


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.


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.


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.)

  OldState: Boolean;
  ResultCode: Integer;
  // 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
    // Turn off redirection, so that cmd.exe from the 64-bit System
    // directory is launched.
    OldState := EnableFsRedirection(False);
      Exec(ExpandConstant('{cmd}'), '', '', SW_SHOW,
        ewWaitUntilTerminated, ResultCode);
      // Restore the previous redirection state.