Tony Camilli

Senior Product Management and Technology Professional

Product Management

Innovation

Design Thinking

Business Model Development

UX & Design

Go-to-Market

Disabling WOW64 File System Redirection from C#

This is a post from my old Blogger-hosted blog.  I've noticed links to it are driving a fair amount of traffic to this site.  Unfortunately, SquareSpace doesn't seem to import old blog posts from Blogger.  So here is the short version of the post, for the long version go here.

Here's what it looks like from unmanaged C++: 

typedef

WINBASEAPI BOOLEAN WINAPI LPFN_ENABLEFSREDIRECTION(BOOLEAN);
...
LPFN_ENABLEFSREDIRECTION *fnEnableFSRedirection;

fnEnableFSRedirection = (LPFN_ENABLEFSREDIRECTION*) GetProcAddress(GetModuleHandle("kernel32"),"Wow64EnableWow64FsRedirection");

if

(NULL != fnEnableFSRedirection)
{

  if

  (fnEnableFSRedirection(bEnable))
  {

    cprintf(TEXT("Success disabling FS Redirection"));

  }
}

else

{

  cprintf(TEXT("Error disabling FS Redirection"));

}

Here's what it looks like in C#:

class Wow64Mgr
{
  [STAThread]
  static void Main(string[] args)
  { 
    try
    {
      if(Wow64Interop.EnableWow64FSRedirection(false))
        Console.WriteLine("WOW64 File System Redirection Disabled");
      else
        Console.WriteLine("Failure Disabling WOW64 File System Redirection");
    }
    catch (Exception exc)
    {
        Console.WriteLine("Failure Setting WOW64 File System Redirection.");
        Console.WriteLine(exc.Message);
    }
  }
}
public class Wow64Interop
{
  [DllImport("Kernel32.Dll", EntryPoint="Wow64EnableWow64FsRedirection")]
  public static extern bool EnableWow64FSRedirection(bool enable);
}