Avoid “File system redirection” in Visual Studio 2012

Windows 8.1 comes with a hidden feature called “Slide to Shutdown”, its like the Slide ti shutdown facility in Windows Phone. Every one was busy in making shortcut for the SlideToShutdown.exe on desktop and calling it via shortcut key combinations. Parallay me, I was studying for the 2nd year 2nd semester end exam. I had different idea rather then making shorcuts and calling it. Mine was a small application that invoke Process class’s Start method C# (ie Process.Start();) or Shell()in VB.net. 

I had my time and started making my idea. There I faced an issue, I used this line of code in C#


But it returned this error

When I put a try catch, the message box pop-up said “The system can not find the file specific”. I tried with VB’s Shell("C:\Windows\System32\Slidetoshutdown.exe") and C’s system("start C:\windows\system32\slidetoshutdown.exe"); but every code returns the same error.

I posted my problem in a forum and some one told me to look up “File System Redirection” and gave me this link. Yes my problem was File system redirection in WIndows.

What is File System Redirection

In the link you can see, 

The %windir%System32 directory is reserved for 64-bit applications. Most DLL file names were not changed when 64-bit versions of the DLLs were created, so 32-bit versions of the DLLs are stored in a different directory. WOW64 hides this difference by using a file system redirector.

In most cases, whenever a 32-bit application attempts to access %windir%System32, the access is redirected to %windir%SysWOW64. Access to %windir%lastgoodsystem32 is redirected to %windir%lastgoodSysWOW64. Access to %windir%regedit.exe is redirected to %windir%SysWOW64regedit.exe.

That is, If I use a 64 bit Windows and calling a 32 bit process, this is subjected to “File System Redirection”. it will actually look in the c:windowssyswow64 directory for the program. The home directory for 32-bit executables. Where it doesn’t exist instead of looking in to c:windowssystem32 directory.

Most of the programs such as “notepad.exe” and “mspaint.exe” resides inside both of these system32 directory and syswow64 directory thats why,


worked for me but unfortunately, “Slidetoshutdown.exe” does not available in syswow64 directory so my code did not workout.

How to disable this file system redirection in Visual studio

In .NET 4.5 and Visual Studio 11 the cheese has been moved. The default for most .NET projects is again AnyCPU, but there is more than one meaning to AnyCPU now. There is an additional sub-type of AnyCPU, “Any CPU 32-bit preferred”, which is the new default (overall, there are now five options for the /platform C# compiler switch: x86, Itanium, x64, anycpu, and anycpu32bitpreferred). When using that flavor of AnyCPU, the semantics are the following:

  • If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on a 64-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on an ARM Windows system, it runs as a 32-bit process. IL is compiled to ARM machine code.

So under Project properties -> Build tab there is a check box available, saying “Prefer 32 bit”.

The difference, then, between “Any CPU 32-bit preferred” and “x86” is only this: a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully.

By default this “Prefer 32 bit” is checked, but to avoid FIle system redirection, we have to un-check it and modify our code like below.


Thats all, your code is gonna work…

If you are using Windows 8.1, you can use my SlideToShutdown application here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s