2013-07-05 39 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