How can disable redirection on win64
Asked Answered
G

1

8

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

Genip answered 5/7, 2013 at 11:17 Comment(0)
I
15

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);
Interrogate answered 5/7, 2013 at 11:33 Comment(1)
Thank you, I don't suppose there is a way to do this in pure .net?Glarum

© 2022 - 2024 — McMap. All rights reserved.