About | Gallery | News | Order the XPT | Products | Resources | Security | Services | Workshop
Home » Workshop » Assorted

The Road We're On

Windows paths and how they work.



Get It

Try It

The concept of the command path - and algorithms for searching a series of directories in a particular order - is endemic to computer use. Here's a brief look at how it works on Wintel boxes.

We've all seen the mightily helpful dialog issued by Windows where we learn that a file - perhaps the name is not even given - that our program needs to run is not found. We're asked to check our paths, our program, dance the jig and try again. Helpful, huh?

So where do these files go when they're no longer found? Where can they be so we can still find them? All of this is laid down very officiously by the Windows operating systems. There is a specific order in which to try different ways to find files our programs need. Windows will always follow this order. If you know and understand this order, you might gain a half step on the rest of the pack.

Here's the order - when looking for most anything, Windows will do as follows.

  1. Search the directory the program loaded from. If the program loaded from C:\Program Files\Acme then no matter what the current working directory (CWD) is, Windows will look there first.
  2. The current working directory (CWD). So if we're in C:\Program Files\Whatever and our program is in C:\Program Files\Acme, and if it needs a file which cannot be found in C:\Program Files\Acme, Windows will look next in C:\Program Files\Whatever.
  3. The 'system' directory. This is normally 'system32' on NTx (at least for now) and 'SYSTEM' on 9x, but it can in theory be named anything at all.
  4. NTx only: The 9x 'system' directory. NTx and 9x system directories can namely coexist, no overwrites necessary.
  5. The 'Windows' directory. By default this is 'Win2K' on 2K systems, 'WinNT' on NT systems, and 'Windows' on 9x systems.
  6. The directories found in the PATH environment variable. And they are searched in the order in which they are found. You can check your environment at any time by going to a command console and typing 'set'. On 9x boxes you can most applicably change this value for your entire system session by adding to autoexec.bat:
    set PATH=C:\My Directory
    On NTx boxes you change this most applicably from the 'Environment' of your 'System' property sheet.
  7. If the Windows shell is starting the program, the 'App Paths' Registry key. The full path to this key is:
    HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths
    Not all methods of starting programs use the Windows shell however, so this source of information is not universally applicable.

It follows then that files do not necessarily have to be where program installers put them. It is rather obvious that the best place for all files for a particular program is the directory where the program is located. Programs - or program suites using different directories - do not need to encroach on system areas so that all their parts can still find all the files. They need only change an environment variable or two or use the 'App Paths' key in the Registry. Whether the Windows shell is used to start the program or not is irrelevant: The programs can themselves search the 'App Paths' key to find the files they need and load them themselves.

It also follows that the user has a certain leeway when it comes to moving files around. If a program installer runs over the proprietary system areas ('Windows' and 'system' directories or below) then the user can move the files back out again.

The only hitch that arises is when the programming team is so lame that they bake absolute paths into their program. E.g. write the program so that the files it needs must absolutely be located in a proprietary system area. If that is the case, it might be a good idea to send the program back and yell a bit. A hitch on that hitch is that Microsoft Visual Basic has traditionally been one of the worst perpetrators here.

Depending on what OS you are running, you might or might not find you can move files around even as they are in use. NT is brilliant at this, keeping track in its process manager database of exactly where each program file is located. 9x is less capable here.

Blobview provides an excellent way to study the way program files will load.

About | Buy | News | Products | Rants | Search | Security
Copyright © Radsoft. All rights reserved.