64位系统上32位进程拷贝文件到System32目录时的重定向

64位系统上,32位进程拷贝文件到"System32"目录时,会被文件系统重定向到"SysWOW64"目录

 

要禁用这种重定向,需要用到下面2个API:

Wow64DisableWow64FsRedirection()
Wow64RevertWow64FsRedirection()

下面是微软的示例代码:
  #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
  
      }
  }

 

参考:

https://msdn.microsoft.com/zh-cn/library/windows/desktop/aa365743%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值