Windows Confidential: History—the Long Way Through

Join our Windows Confidential columnist for a decidedly roundabout tour of all the directories with the word “system” in their name.

Raymond Chen

Once upon a time, back in the days of 16-bit Windows, there was a directory named C:\Windows\System. That was the last time things were simple.

With the introduction of Win32, there was a second system directory added named C:\Windows\System32. This second directory contained the 32-bit system files. The 16-bit system files remained in the old system directory. Well, except that on Windows 95, both 32-bit and 16-bit system files lived in the same directory, which retained its old name of C:\Windows\System. We shall not speak of Windows 95 again.

Batch files ran programs from C:\Windows\System32 with the expectation that the resulting program would match the native OS. These expectations were not explicit, but they were implied by the nature of the activity. If the System32 directory were filled with 32-bit programs, then a batch file that ran the C:\Windows\System32\REG.EXE program to upset a system registry setting would be running the 32-bit version of REG.EXE, which means that it would be updating the 32-bit simulated version of the registry instead of the real 64-bit version. Other types of scripting files (such as REG files) have the same problem.

There are quite a number of existing 32-bit programs that hard-code the System32 path rather than calling the GetSystemDirectory function. When these programs are recompiled for 64-bit Windows, they will still try to access the System32 directory, expecting to find 64-bit files (because the program is now compiled 64-bit). Paths written into configuration files or the registry need to be meaningful to both 32-bit and 64-bit processes, yet need to refer to the appropriate directory depending on the “bitness” of the program doing the asking.

Clear as Mud?

To extricate itself from this confusing situation, the Windows team decided to have the System32 directory contain 64-bit files on 64-bit systems and 32-bit files on 32-bit systems. The 32 is just part of the name and doesn’t mean anything. It’s similar to how DVD is just a name and doesn't really mean anything, or how many large companies officially change their name to a sequence of letters which may have at one time stood for something but now just form a name, like HSBC, KFC, BP and KPMG.

File system redirection for 32-bit processes adds another layer of complexity to this already-confusing story. When a 32-bit process accesses the C:\Windows\System32 directory on a 64-bit system, its operations are redirected to the C:\Windows\SysWOW64 directory, which is where you’ll find the 32-bit system DLLs.

As a result, you should think of System32 as the somewhat strange name for the “system DLLs in the same bitness as the application that’s running” directory. In a more ideal world, something like this would have been called the SysExec directory because it contains files matching the execution environment.

But Wait, There’s More

What if you want to access the real 64-bit system directory from a 32-bit process? File system redirection will take your attempt to access the C:\Windows\System32 directory and redirect it to the C:\Windows\SysWOW64 directory. Programmatically, you can use functions with unwieldy names like Wow64­Disable­Wow64­Fs­Redirection, but those disable redirection for all operations until they’re re-enabled. This causes trouble if you’re doing anything more complicated than opening a single file. Performing a complex operation may result in accessing multiple files or possibly creating worker threads.

That's the end of our roundabout tour of the various directories with System in their name. If it seems confusing, just remember that the meaning of the directory rarely matches its name.

Raymond Chen

Raymond Chen's* Web site, The Old New Thing, and identically titled book (Addison-Wesley, 2007) deals with Windows history, Win32 programming and the illusory repair powers of black electrical tape.*