比较实用的就是获取Program Files的目录,这个目录当系统装在不同的盘下,或者64位系统下都会不同,hard code是最差的办法了。
使用CSIDL_PROGRAM_FILES参数动态获取这个路径。
特别地,CSIDL_PROGRAM_FILES,在64位系统下面,如果你的程序是32位的,这个参数仍然会定位到C:\Program Files (x86)
http://msdn.microsoft.com/en-us/library/bb762204%28v=VS.85%29.aspx
Syntax
BOOL SHGetSpecialFolderPath( HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate );
Parameters
hwndOwner
- A handle to the owner window that the client should specify if it displays a dialog box or message box.
lpszPath- A pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
nFolder- A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.
fCreate- Indicates whether the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.
Return Value
Returns TRUE if successful, or FALSE otherwise.
-
CSIDL_ADMINTOOLS (FOLDERID_AdminTools)
- Version 5.0. The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user. CSIDL_ALTSTARTUP (FOLDERID_Startup)
- The file system directory that corresponds to the user's nonlocalized Startup program group. This value is recognized in Windows Vista for backward compatibility, but the folder itself no longer exists. CSIDL_APPDATA (FOLDERID_RoamingAppData)
- Version 4.71. The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\ username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed. CSIDL_BITBUCKET (FOLDERID_RecycleBinFolder)
- The virtual folder that contains the objects in the user's Recycle Bin. CSIDL_CDBURN_AREA (FOLDERID_CDBurning)
- Version 6.0. The file system directory that acts as a staging area for files waiting to be written to a CD. A typical path is C:\Documents and Settings\ username\Local Settings\Application Data\Microsoft\CD Burning. CSIDL_COMMON_ADMINTOOLS (FOLDERID_CommonAdminTools)
- Version 5.0. The file system directory that contains administrative tools for all users of the computer. CSIDL_COMMON_ALTSTARTUP (FOLDERID_CommonStartup)
- The file system directory that