Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can disable redirection on win64

Tags:

redirect

c#

win64

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

like image 596
happy Avatar asked Jul 05 '13 11:07

happy


1 Answers

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);
like image 185
master131 Avatar answered Oct 27 '22 23:10

master131