How can disable redirection on win64

2020-02-11 05:19发布

I want to copy c:\Windows\regedit.exe to same directory with regedit2.exe name But when I try to copy it,I take an error which say regedit.exe file not found" or sometimes copy it to under windows\SysWOW64 directory. And actually I knıow win64 is redirecting it But how can I disable redirecting and copy windows/regedit.exe to windows/regedit2.exe. My sample code is

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

İs there any one who can help me

1条回答
劳资没心,怎么记你
2楼-- · 2020-02-11 06:06

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);
查看更多
登录 后发表回答