HOWTO: Determine the Current Location of Files or Folders on Windows 2000

ID: Q227051

This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about obtaining support for a Beta release, please see the documentation included with the Beta product files, or check the Web location from which you downloaded the release.
The information in this article applies to:


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:

Q222193 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.

Additional query words: compatguidesetup compatguidestability


Keywords          : kbWinOS2000 kbGrpUser 
Version           : winnt:
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: May 25, 1999