源码:
- #include <Shlobj.h>
- #include <stdio.h>
- #include <locale.h>
- int main()
- {
- setlocale(LC_ALL, "chs");
- TCHAR szPath[MAX_PATH];
- int CSIDL[] = {
- CSIDL_ADMINTOOLS, CSIDL_APPDATA, CSIDL_CDBURN_AREA, CSIDL_COMMON_ADMINTOOLS, CSIDL_COMMON_APPDATA,
- CSIDL_COMMON_DESKTOPDIRECTORY, CSIDL_COMMON_DOCUMENTS, CSIDL_COMMON_FAVORITES, CSIDL_COMMON_MUSIC,
- CSIDL_COMMON_PICTURES, CSIDL_COMMON_PROGRAMS, CSIDL_COMMON_STARTMENU, CSIDL_COMMON_STARTUP,
- CSIDL_COMMON_TEMPLATES, CSIDL_COMMON_VIDEO, CSIDL_COOKIES, CSIDL_FAVORITES,
- CSIDL_HISTORY, CSIDL_INTERNET_CACHE, CSIDL_LOCAL_APPDATA, CSIDL_MYDOCUMENTS,
- CSIDL_MYMUSIC, CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_PROFILE, CSIDL_PROGRAM_FILES,
- CSIDL_PROGRAM_FILES_COMMON, CSIDL_PROGRAMS, CSIDL_RECENT, CSIDL_SENDTO,
- CSIDL_STARTMENU, CSIDL_STARTUP, CSIDL_SYSTEM, CSIDL_TEMPLATES, CSIDL_WINDOWS,
- 0
- };
- for (int i=0;CSIDL[i];i++) {
- if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL[i], NULL, SHGFP_TYPE_CURRENT, szPath))) {
- wprintf(L"%d, %s ", i, szPath);
- }
- }
- return 0;
- }
在XP上,用VS2010编译通过,假设是win7或者更高版本号,应该用
- HRESULT SHGetKnownFolderPath(
- _In_ REFKNOWNFOLDERID rfid,
- _In_ DWORD dwFlags,
- _In_opt_ HANDLE hToken,
- _Out_ PWSTR *ppszPath
- );
结果:
- 0, C:Documents and SettingsAdministrator「開始」菜单程序管理工具
- 1, C:Documents and SettingsAdministratorApplication Data
- 2, C:Documents and SettingsAdministratorLocal SettingsApplication DataMicrosoftCD Burning
- 3, C:Documents and SettingsAll Users「開始」菜单程序管理工具
- 4, C:Documents and SettingsAll UsersApplication Data
- 5, C:Documents and SettingsAll Users桌面
- 6, C:Documents and SettingsAll UsersDocuments
- 7, C:Documents and SettingsAll UsersFavorites
- 8, C:Documents and SettingsAll UsersDocumentsMy Music
- 9, C:Documents and SettingsAll UsersDocumentsMy Pictures
- 10, C:Documents and SettingsAll Users「開始」菜单程序
- 11, C:Documents and SettingsAll Users「開始」菜单
- 12, C:Documents and SettingsAll Users「開始」菜单程序启动
- 13, C:Documents and SettingsAll UsersTemplates
- 14, C:Documents and SettingsAll UsersDocumentsMy Videos
- 15, D:My DocumentsCookies
- 16, D:My DocumentsFavorites
- 17, C:Documents and SettingsAdministratorLocal SettingsHistory
- 18, C:Documents and SettingsAdministratorLocal SettingsTemporary Internet Files
- 19, C:Documents and SettingsAdministratorLocal SettingsApplication Data
- 20, D:My Documents
- 21, D:My DocumentsMy Music
- 22, D:My DocumentsMy Pictures
- 23, D:My DocumentsMy Videos
- 24, C:Documents and SettingsAdministrator
- 25, C:Program Files
- 26, C:Program FilesCommon Files
- 27, C:Documents and SettingsAdministrator「開始」菜单程序
- 28, C:Documents and SettingsAdministratorRecent
- 29, C:Documents and SettingsAdministratorSendTo
- 30, C:Documents and SettingsAdministrator「開始」菜单
- 31, C:Documents and SettingsAdministrator「開始」菜单程序启动
- 32, C:WINDOWSsystem32
- 33, C:Documents and SettingsAdministratorTemplates
- 34, C:WINDOWS