2013-07-05 40 views
1

禁用重定向我想c:\Windows\regedit.exe复制到同一目录与regedit2.exe名但是当我试图复制它,我把它说regedit.exe找不到文件”或有时错误windows\SysWOW64目录下复制到。而实际上我knıowwin64被重定向,但我如何禁用重定向和复制窗口/ REGEDIT.EXE到windows/regedit2.exe。我的示例代码如何Win64上

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

没有任何一个谁可以帮我

回答

4

有是可用的Win32函数,可以禁用和启用redi rection。

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

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

例子:

IntPtr wow64Value = IntPtr.Zero; 

// Disable redirection. 
Wow64DisableWow64FsRedirection(ref wow64Value); 

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

// Re-enable redirection. 
Wow64RevertWow64FsRedirection(wow64Value); 
+0

我会尽力感谢ü这么多 – happy

+0

谢谢,我不认为有一种方法在纯.NET做到这一点? – WHol