14

My OS is 64 bits and in the foler C:\Windows\SysWOW64 there is a file 111.txt, but there is not the file in c:\windows\system32

but the follwoing code return true

file = @"C:\Windows\System32\111.txt";    
bool bExist = System.IO.File.Exists(file);

I don't know why? and how can i check if there is the file 111.txt under system32 not SysWoW64?

2 Answers 2

16

Because so many applications have hard-coded the System32 directory name into paths, MS put the 64-bit systems files there instead of in a 'System64' directory. The 32-bit versions now go into a 'SysWOW64' directory (it's quite confusing). but in order to prevent breaking 32-bit programs, the system performs a redirection by default for 32-bit processes trying to access the 'System32' directory. In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.

A simple way to get around this redirection is to use %windir%\Sysnative instead of %windir%\System32. Win64 will 'redirect' that directory to the actual System32 directory.

You can use the Wow64DisableWow64FsRedirection() API to completely disable this redirection . See http://msdn.microsoft.com/en-us/library/aa384187.aspx for details.

1
  • Thank you a lot. For the record I found out that using this meta dir "sysnative" is not reliable, it does not always work as expected. I manually checked if the OS is 32-bit o 64-bit, and picked manually subdir. Commented Dec 24, 2014 at 14:07
5

32bit processes see the contents of the C:\Windows\SysWOW64 directory when they ask for the C:\Windows\System32 directory.

Additionally, when trying to save a file to C:\Windows\System32, it will end up in C:\Windows\SysWOW64.

However, unless you are writing an installer-type of program, you probably do not want to mess with these directories at all. All the binaries in C:\Windows\System32 are 64bit and not usable from 32bit processes. That's why the request for them is redirected to C:\Windows\SysWOW64 in the first place.

Edit: If you really want to see the files, use Wow64DisableWow64FsRedirection via PInvoke.

2
  • 5
    It's just like good old Microsoft to put 64-bit binaries in a folder ending with "32" and 32-bit binaries in one ending with "64". Yes, I know that WOW64 stands for "Windows on Windows 64", but the naming choice is still aweful. Commented Jan 29, 2010 at 8:35
  • 4
    So it is Microsoft's fault that so many programmers hard-coded "system32"? Commented Jan 29, 2010 at 9:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.