On all 64-bit versions of Windows, the operating system performs a few file system and registry tricks for 32-bit applications. Essentially, operations targeting certain locations are transparently redirected to separate locations to allow applications that might not even know they’re on a 64-bit machine to interact with a more predictable environment.
The functioning of 32-bit applications on 64-bit Windows is described in detail in MSDN. The short version is that when applications are looking for files into C:Program Files, they’re transparently redirected to C:Program Files (x86). The same goes for C:WindowsSystem32, which contains the 64-bit Windows binaries and is redirected to C:WindowsSysWOW64 (the destination for the 32-bit equivalents). Same for a bunch of other file locations and registry hives, subject to a few caveats.
Sometimes it is necessary for 64-bit aware x86 code to get out of its shell and reach out to the true 64-bit locations. For application code, it’s quite easy to work around both the file system and the registry redirector. To access an alternate view of the registry (32-bit from a 64-bit app or viceversa), you need to remember the KEY_WOW64_64KEY and KEY_WOW64_32KEY flags, and to access the true 64-bit directories, a few API calls must be made. But here’s the fun part:
If you write a script (batch, or JavaScript/VBScript), it’s easy to tell if you’re running in a native 64-bit command processor or in the WOW, but there’s almost no way to work with the 64-bit files and registry locations from a script running as 32-bit if the host doesn’t help you.
Starting with Vista, there’s a very simple way to reach the true System32 directory from the WOW: Look for %WINDIR%sysnative. This is a virtual directory available only to 32-bit applications on 64-bit operating systems which points to the true %WINDIR%System32. Let’s try it out:
Launch %WINDIR%SysWOW64Cmd.exe (the 32-bit command prompt). Let’s see if anything exists under %WINDIR%sysnative:
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:>if exist %WINDIR%sysnativereg.exe echo Foo
Foo
C:>
On the other hand, if you run the same command from a 64-bit command prompt launched from %WINDIR%System32Cmd.exe:
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:>if exist %WINDIR%sysnativereg.exe echo Foo
C:>
It’s as simple as that. If you need to modify the 64-bit registry from a script running under the 32-bit host, all you need is to invoke reg.exe from the sysnative directory. Better yet, you can come up with batch files that re-launch themselves with the 64-bit command interpreter on a 64-bit OS. All you need to do is look for %WINDIR%sysnativecmd.exe, after all.
Reference: http://ovidiupl.spaces.live.com/blog/cns!1E8A6038167E4BE9!925.entry