The x64 version of Windows is not capable of natively running 32-bit code. Because most applications are 32-bit,...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
the x64 version of Windows makes use of an emulator known as WOW64 to allow 32-bit applications to run.
One of the problems with running 32-bit code on a 64-bit operating system is that the OS must maintain complete code separation. Microsoft has created a new folder named \Windows\SysWOW64 that is used to store the 32-bit DLLs. In the 32-bit version of Windows, DLL files are normally stored in the \windows\system32 folder. However, the x64 version of Windows uses the \windows\system32 folder for 64-bit DLLs.
As you can see, the WOW64 emulator must perform file system redirection in order to guarantee that 32- and 64-bit code remain separated. But keeping DLL files separated is only the beginning. The WOW64 emulator performs file system redirection for several key components of the Windows operating system.
Another location in Windows where file system redirection is used is the Program Files folder. Almost every application you install it gets installed to the C:\Program Files folder. Because each application is installed in a separate subfolder, the Program Files folder seems like an unlikely target for file system redirection. However, in the x64 version of Windows, only 64-bit applications are usually installed in the Program Files folder -- 32-bit applications are installed in a folder named Program Files (x86).
However, the Program Files folder may not always be in the same place on every computer. I have seen deployments (admittedly few and far between) in which Windows was installed on a secondary hard drive. As such, most application developers do not hard-code the c:\Program Files path into applications. Instead, Setup programs usually make a call to an OS function known as SHGetSpecialFolder() in order to determine the exact name and location of the Program Files folder. Although this bit of information may seem trivial, it is useful in making sure that applications are installed to the correct folder.
In the 32-bit version of Windows, the SHGetSpecialFolder() function is used to determine the name and location of the Program Files folder. But in the x64 version, the function looks at whether the Setup application was running 32- or 64-bit code and performs folder redirection based on that application.
Application installation is not the only time when the Program Files folder is referenced; it may also be referenced during application run time. Although there are several ways that an application can determine the name and location of the Program Files folder, environment variables are often used. In a 32-bit version of Windows, the %ProgramFiles% environment variable contains the path to the Program Files folder. In an x64 version of Windows, this environment variable is still used, but it works differently.
The most important rule of the x64 platform is that you absolutely cannot mix 64- and 32-bit code. Environment variables are often called from within scripts. That being the case, running scripts can get a bit tricky in a 64-bit environment. Should Windows treat the script as 32-bit code or as 64-bit code? The answer affects not only the contents of the environment variables, but also which external programs the script can call. For example, a 64-bit script can't launch a 32-bit process (at least not in the usual way).
Windows gets around these issues by offering two command prompts: one 64-bit and one 32-bit. Environment variables are set according to which command environment is being used.
For example, if you open a command prompt by entering the CMD.EXE command at the Run prompt, Windows will open a 64-bit command prompt. In most cases, the %ProgramFiles% environment variable for the command environment will be set to C:\Program Files. If you run a script, the script can interact with 64-bit applications, but not with 32-bit apps.
On the flip side, if you enter the C:\Windows\SysWOW64\cmd.exe command at the run prompt, you'll be running a 32-bit command prompt. In that case, the %ProgramFiles% environment variable will be set to C:\Program Files (x86).
As you can see, the location of the Program Files folder is redirected depending on whether you're running 32- or 64-bit code. But there's one exception to this rule. If an application has the C:\Program Files path hard-coded, then C:\Program Files will be used, even if the application is made up of 32-bit code. Folder redirection does not occur for hard-coded paths. Fortunately, hard-coding paths is not a common programming practice.
About the author: Brien M. Posey, MCSE, is a Microsoft Most Valuable Professional for his work with Windows 2000 Server, Exchange Server and IIS. He has served as CIO for a nationwide chain of hospitals and was once in charge of IT security for Fort Knox. He writes regularly for SearchWinComputing.com and other TechTarget sites.
More information on this topic:
- Tip: Hardware driver, app issues can gum up move to x64 Windows
- Topics: Windows server management
- RSS: Sign up for our RSS feed to receive expert advice every day.