7

我想c:\Windows\regedit.exe用名称复制到同一个目录regedit2.exe但是当我尝试复制它时,我会出错,说regedit.exe找不到文件“或者有时将它复制到windows\SysWOW64目录下。实际上我知道win64正在重定向它但是我怎样才能禁用重定向和复制windows/regedit.exe 到 windows/regedit2.exe。我的示例代码是

if(File.Exists(@"c:\Windows\regedit.exe"))
try
{
File.Copy(@"c:\Windows\regedit.exe", @"c:\Windows\regedit2.exe", true);
}
catch (Exception ex){}

有没有人可以帮助我

4

1 回答 1

14

There are Win32 functions available that can disable and enable redirection.

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

Example:

IntPtr wow64Value = IntPtr.Zero;

// Disable redirection.
Wow64DisableWow64FsRedirection(ref wow64Value);

// Do whatever you need
// .....................

// Re-enable redirection.
Wow64RevertWow64FsRedirection(wow64Value);
于 2013-07-05T11:33:08.107 回答