控制Wow64重定向
作者:互联网
参考:https://blog.csdn.net/karlxzy/article/details/42170419
在默认情况下,64位环境运行32位程序,会启用重定向,
比如 调用CreateFile时,系统会把system32文件夹重定向到Syswow64等等。
但是有些时候需要访问system32文件夹的时候就需要关闭重定向。
MS已经提供了一组函数用来控制重定向:
Wow64EnableWow64FsRedirection
Wow64DisableWow64FsRedirection
Wow64RevertWow64FsRedirection
用法在MSDN里面有DEMO:
- #define _WIN32_WINNT 0x0501
- #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
- }
- }
标签:控制,Wow64,HANDLE,重定向,redirection,OldValue,NULL,hFile 来源: https://www.cnblogs.com/kuangke/p/14702551.html