How To Determine the Current Location of Files or Folders on Windows 2000 (227051)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 2000

This article was previously published under Q227051

SUMMARY

When you are trying to find special files or folders programmatically, use the SHGetFolderPath API or one of the system APIs for the most reliable information. Though you can determine the location of the Windows System folder, your application should not install files there.

MORE INFORMATION

When creating an application or custom Setup program, it isn't safe to assume that all systems have the same configuration. There are a number of folders that are used frequently by applications, but they may not have the same name or location. For example, the system root folder may be "C:\Windows" on one system and "D:\Windows" or "C:\Winnt" on another. For this reason, you should not hard code paths to files or folder in your application.

You can determine the location of special folders on a given system by using SHGetFolderPath, or the Windows API functions GetSystemDirectory and GetWindowsDirectory. You can also use the ExpandEnvironmentStrings function and environmental variables to identify certain folders, though GetSystemDirectory and GetWindowsDirectory sometimes return more current information than environment variables.

If you are developing an application on Windows 2000, the SHGetFolderPath function is the most robust option for retrieving information about special folders. The SHGetFolderPath function will return the location of most special folders, including Program Files and the system root folder. SHGetFolderPath accepts CSIDL values, which provide a unique system-independent way to identify special folders. Consult the Platform SDK documentation for a complete list of folders that the SHGetFolderPath function can identify.

Important: SHGetFolderPath is new to the Windows 2000 API. If you call SHGetFolderPath from an application that can be installed on a previous version of Windows, then you will need to redistribute the file SHFolder.dll with your application.

Though you can identify the location of the system folder with system information functions or environmental variables, you should not install files there. Windows 2000 System File Protection prevents you from replacing or updating essential system files.

REFERENCES

For additional information about System File Protection, please see the following article in the Microsoft Knowledge Base:

222193 Description of the Windows 2000 System File Protection Feature

For more information on environment variables or Windows System Information API functions, consult the Platform SDK documentation.

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbhowto KB227051