March 1999

How Windows locates files

by Kent Reisdorph

In the article, "Spawning external applications," we passed filenames or document files to the WinExec, ShellExecute, and CreateProcess functions. These functions allow you to pass a fully qualified path and filename or just the filename itself. If just a filename is passed, Windows will attempt to locate the file. Windows searches for the file in the following order:

  1. The directory where the application resides.
  2. The current directory.
  3. The Windows system directory (SYSTEM for Windows 95 and 98, and SYSTEM32 for Windows NT).
  4. The Windows 16-bit system directory, usually called SYSTEM (NT only).
  5. The Windows root directory.
  6. The directories on the system path (listed in the PATH environment variable).

If the application being spawned doesn't reside in any of the directories listed above, you must fully qualify the path and filename to the application.