Tip: Retrieving Folder Paths from the Registry

I wrote the following set of functions to retrieve standard folder locations from the Windows Registry, without having to cut and paste the complex syntax into every procedure where I need to use the Windows | Office | Templates or Documents folder as part of a file path. Each folder path is returned as a string terminated with a backslash.

To use these routines, copy the code into any application where you need to use these paths, and call the function as follows:

Here’s the standard routine, which works by using Word’s System property:

The key lies in the second and third parameters passed to the PrivateProfileString method. The parameters used in the preceding routine returns the Windows directory. Table 1 lists the parameters for some other interesting directories.

Table 1. Keys for retrieving directory names from the Windows Registry.

Directory Second parameter Third parameter
Office HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0 BinDirPath
Documents HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders Personal
Templates HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Common\FileNew\LocalTemplates


About Helen Feddema

Helen is the editor of Access Watch, a more or less biweekly ezine. She lives in the mid-Hudson area of New York state, with two cats and three computers.
This entry was posted in User Interface (UI). Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.