API聲明: function ulong SHGetSpecialFolderPath(long hwndOwner,ref string lpszPath,int nFolder,boolean fCreate ) LIBRARY "shell32.dll" ALIAS FOR "SHGetSpecialFolderPathA"
Function Long GetDesktopWindow() Library 'user32.dll'
hwndOwner :可用GetDesktopWindow API取一個視窗句柄。或直接傳null.
lpszPath:返迴路徑的緩衝區
nFolder:標識代號
fCreate:true :如果資料夾不存在則創建,false:不創建
lpszPath和nFolder對應關係:
| nFolder | lpszPath |
| 0 | C:/Documents and Settings/當前用戶/桌面 |
| 2 | C:/Documents and Settings/當前用戶/「開始」選單/程式 |
| 5 | C:/Documents and Settings/當前用戶/My Documents |
| 6 | C:/Documents and Settings/當前用戶/Favorites |
| 7 | C:/Documents and Settings/當前用戶/「開始」選單/程式/啟動 |
| 8 | C:/Documents and Settings/當前用戶/Recent |
| 9 | C:/Documents and Settings/當前用戶/SendTo |
| 11 | C:/Documents and Settings/當前用戶/「開始」選單 |
| 13 | C:/Documents and Settings/當前用戶/My Documents/My Music |
| 14 | C:/Documents and Settings/當前用戶/My Documents/My Videos |
| 16 | C:/Documents and Settings/當前用戶/桌面 |
| 19 | C:/Documents and Settings/當前用戶/NetHood |
| 20 | C:/WINDOWS/Fonts |
| 21 | C:/Documents and Settings/當前用戶/Templates |
| 22 | C:/Documents and Settings/All Users/「開始」選單 |
| 23 | C:/Documents and Settings/All Users/「開始」選單/程式 |
| 24 | C:/Documents and Settings/All Users/「開始」選單/程式/啟動 |
| 25 | C:/Documents and Settings/All Users/桌面 |
| 26 | C:/Documents and Settings/當前用戶/Application Data |
| 27 | C:/Documents and Settings/當前用戶/PrintHood |
| 28 | C:/Documents and Settings/當前用戶/Local Settings/Application Data |
| 31 | C:/Documents and Settings/All Users/Favorites |
| 32 | C:/Documents and Settings/當前用戶/Local Settings/Temporary Internet Files |
| 33 | C:/Documents and Settings/當前用戶/Cookies |
| 34 | C:/Documents and Settings/當前用戶/Local Settings/History |
| 35 | C:/Documents and Settings/All Users/Application Data |
| 36 | C:/WINDOWS |
| 37 | C:/WINDOWS/system32 |
| 38 | C:/Program Files |
| 39 | C:/Documents and Settings/當前用戶/My Documents/My Pictures |
| 40 | C:/Documents and Settings/當前用戶 |
| 43 | C:/Program Files/Common Files |
| 45 | C:/Documents and Settings/All Users/Templates |
| 46 | C:/Documents and Settings/All Users/Documents |
| 47 | C:/Documents and Settings/All Users/「開始」選單/程式/管理工具 |
| 48 | C:/Documents and Settings/當前用戶/「開始」選單/程式/管理工具 |
| 53 | C:/Documents and Settings/All Users/Documents/My Music |
| 54 | C:/Documents and Settings/All Users/Documents/My Pictures |
| 55 | C:/Documents and Settings/All Users/Documents/My Videos |
| 56 | C:/WINDOWS/resources |
| 59 | C:/Documents and Settings/當前用戶/Local Settings/Application Data/Microsoft/CD Burning |
#include <shlobj.h>
#pragma comment(lib, "shell32.lib")
TCHAR szPath[max_path];
SHGetSpecialFolderPath(NULL,szPath,csidl_COMMON_DOCUMENTS, FALSE);
// szPath 就是對於這個函式MSDN:使用說明:這裡面的CSIDL可能有些使用不正常,最好參考本地SHLOBJ.H檔案裡面的定義使用保證能using,:)
TCHAR szPath[MAX_PATH];
SHGetSpecialFolderPath(NULL,szPath,CSIDL_APPDATA,FALSE);
MessageBox(NULL,szPath,"當前用戶配置路徑",MB_ICONSTOP);
VB6
聲明(Declare)
Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
