Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
Local File Systems
File Management
 Wow64DisableWow64FsRedirection func...
Wow64DisableWow64FsRedirection function

Applies to: desktop apps only

Disables file system redirection for the calling thread. File system redirection is enabled by default.

Syntax

BOOL WINAPI Wow64DisableWow64FsRedirection(
  __out  PVOID *OldValue
);

Parameters

OldValue [out]

The WOW64 file system redirection value. The system uses this parameter to store information necessary to revert (re-enable) file system redirection.

Note  This value is for system use only. To avoid unpredictable behavior, do not modify this value in any way.

Return value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This function is useful for 32-bit applications that want to gain access to the native system32 directory. By default, WOW64 file system redirection is enabled.

The Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection function pairing is a replacement for the functionality of the Wow64EnableWow64FsRedirection function.

To restore file system redirection, call the Wow64RevertWow64FsRedirection function. Every successful call to the Wow64DisableWow64FsRedirection function must have a matching call to the Wow64RevertWow64FsRedirection function. This will ensure redirection is re-enabled and frees associated system resources.

Note  The Wow64DisableWow64FsRedirection function affects all file operations performed by the current thread, which can have unintended consequences if file system redirection is disabled for any length of time. For example, DLL loading depends on file system redirection, so disabling file system redirection will cause DLL loading to fail. Also, many feature implementations use delayed loading and will fail while redirection is disabled. The failure state of the initial delay-load operation is persisted, so any subsequent use of the delay-load function will fail even after file system redirection is re-enabled. To avoid these problems, disable file system redirection immediately before calls to specific file I/O functions (such as CreateFile) that must not be redirected, and re-enable file system redirection immediately afterward using Wow64RevertWow64FsRedirection.

Disabling file system redirection affects only operations made by the current thread. Some functions, such as CreateProcessAsUser, do their work on another thread, which is not affected by the state of file system redirection in the calling thread.

Examples

The following example uses Wow64DisableWow64FsRedirection to disable file system redirection so that a 32-bit application that is running under WOW64 can open the 64-bit version of Notepad.exe in %SystemRoot%\System32 instead of being redirected to the 32-bit version in %SystemRoot%\SysWOW64.

C++
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501

#ifdef NTDDI_VERSION
#undef NTDDI_VERSION
#endif
#define NTDDI_VERSION 0x05010000

#include <Windows.h>

void main()
{
    HANDLE hFile = INVALID_HANDLE_VALUE;
    PVOID OldValue = NULL;

    //  Disable redirection immediately prior to the native API
    //  function call.
    if( Wow64DisableWow64FsRedirection(&OldValue) ) 
    {
        //  Any function calls in this block of code should be as concise
        //  and as simple as possible to avoid unintended results.
        hFile = CreateFile(TEXT("C:\\Windows\\System32\\Notepad.exe"),
            GENERIC_READ,
            FILE_SHARE_READ,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

        //  Immediately re-enable redirection. Note that any resources
        //  associated with OldValue are cleaned up by this call.
        if ( FALSE == Wow64RevertWow64FsRedirection(OldValue) )
        {
            //  Failure to re-enable redirection should be considered
            //  a criticial failure and execution aborted.
            return;
        }
    }
    
    //  The handle, if valid, now can be used as usual, and without
    //  leaving redirection disabled. 
    if( INVALID_HANDLE_VALUE != hFile )  
    {
        // Use the file handle
    }
}

Requirements

Minimum supported client

Windows Vista, Windows XP Professional x64 Edition

Minimum supported server

Windows Server 2008, Windows Server 2003 with SP1

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

File Management Functions
File System Redirector
Wow64EnableWow64FsRedirection
Wow64RevertWow64FsRedirection

 

 

Send comments about this topic to Microsoft

Build date: 4/17/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
comment      Huang Pointer   |   Edit   |   Show History
Thank for your opinions. I think you still can use it for where you need it. Just turn it on after finishing your job.
Tags What's this?: Add a tag
Flag as ContentBug
How to do it the right way!      ElmueSoft   |   Edit   |   Show History
As the MSDN says:

"Disabling file system redirection affects only operations made by the current thread.
Some functions, such as CreateProcessAsUser, do their work on another thread,
which is not affected by the state of file system redirection in the calling thread."

This is a typical situation: Microsft lets us programmers alone with this sentence.
And how to solve the problem if I want to start a process with CeateProcessAsUser and I NEED to turn off FileSystemRedirection ???
So what do I do ?
Why don't they write that ?
Again: The MSDN is no help.
So I use Google in the hope that anybody already solved it.

I spent a lot of time searching around and it seems that the best you can do is forget this API completely!
Forget disabling and reverting file redirection at all !!

You will run in to problems everywhere:
For example I used mciSendString(open....)  to play a sound file.
Forget it!
MCI will not find the sound drivers anymore if you turn off redirection.

Additionally you have the Registry redirection with the Wow6432 node which is another problem!

You create more problems than you solve with this Wow64DisableWow64FsRedirection and the other turn-off-redirection APIs !!

The only bulletproof solution is to compile your application as a 64 Bit application and youre done!
Don't waste your time with these dirty workarounds !

Elmü

Tags What's this?: Add a tag
Flag as ContentBug
Some APIs depend on FileSystemRedirection!      ElmueSoft   |   Edit   |   Show History
ATTENTION:
In a 32 Bit application on 64 Bit Windows GetOpenFilename, GetSaveFilename and ShBrowseForFolder must NOT be called after Wow64DisableWow64FsRedirection!
Otherwise no window or a crippled window will open.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker