Private Const CSIDL_COOKIES = &H21&
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
MKid As SHITEMID
End Type
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim IDL As ITEMIDLIST
'Get the special folder
Dim Path As String
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NO_ERROR Then
'Create a buffer
Path = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.MKid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function
Private Sub Command1_Click()
Dim Path As String
Path = GetSpecialfolder(CSIDL_COOKIES) '获取COOKIES文件夹路径
MsgBox Path
End Sub
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
MKid As SHITEMID
End Type
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim IDL As ITEMIDLIST
'Get the special folder
Dim Path As String
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NO_ERROR Then
'Create a buffer
Path = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.MKid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function
Private Sub Command1_Click()
Dim Path As String
Path = GetSpecialfolder(CSIDL_COOKIES) '获取COOKIES文件夹路径
MsgBox Path
End Sub
|
tiancao1001 于 2009-01-06 04:56 PM 发表评论:
Private Enum CSIDL_VALUES
CSIDL_DESKTOP = &H0
CSIDL_INTERNET = &H1
CSIDL_PROGRAMS = &H2
CSIDL_CONTROLS = &H3
CSIDL_PRINTERS = &H4
CSIDL_PERSONAL = &H5
CSIDL_FAVORITES = &H6
CSIDL_STARTUP = &H7
CSIDL_RECENT = &H8
CSIDL_SENDTO = &H9
CSIDL_BITBUCKET = &HA
CSIDL_STARTMENU = &HB
CSIDL_MYDOCUMENTS = &HC
CSIDL_MYMUSIC = &HD
CSIDL_MYVIDEO = &HE
CSIDL_DESKTOPDIRECTORY = &H10
CSIDL_DRIVES = &H11
CSIDL_NETWORK = &H12
CSIDL_NETHOOD = &H13
CSIDL_FONTS = &H14
CSIDL_TEMPLATES = &H15
CSIDL_COMMON_STARTMENU = &H16
CSIDL_COMMON_PROGRAMS = &H17
CSIDL_COMMON_STARTUP = &H18
CSIDL_COMMON_DESKTOPDIRECTORY = &H19
CSIDL_APPDATA = &H1A
CSIDL_PRINTHOOD = &H1B
CSIDL_LOCAL_APPDATA = &H1C
CSIDL_ALTSTARTUP = &H1D
CSIDL_COMMON_ALTSTARTUP = &H1E
CSIDL_COMMON_FAVORITES = &H1F
CSIDL_INTERNET_CACHE = &H20
CSIDL_COOKIES = &H21
CSIDL_HISTORY = &H22
CSIDL_COMMON_APPDATA = &H23
CSIDL_WINDOWS = &H24
CSIDL_SYSTEM = &H25
CSIDL_PROGRAM_FILES = &H26
CSIDL_MYPICTURES = &H27
CSIDL_PROFILE = &H28
CSIDL_SYSTEMX86 = &H29
CSIDL_PROGRAM_FILESX86 = &H2A
CSIDL_PROGRAM_FILES_COMMON = &H2B
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
CSIDL_COMMON_TEMPLATES = &H2D
CSIDL_COMMON_DOCUMENTS = &H2E
CSIDL_COMMON_ADMINTOOLS = &H2F
CSIDL_ADMINTOOLS = &H30
CSIDL_CONNECTIONS = &H31
CSIDL_COMMON_MUSIC = &H35
CSIDL_COMMON_PICTURES = &H36
CSIDL_COMMON_VIDEO = &H37
CSIDL_RESOURCES = &H38
CSIDL_RESOURCES_LOCALIZED = &H39
CSIDL_COMMON_OEM_LINKS = &H3A
CSIDL_CDBURN_AREA = &H3B
CSIDL_COMPUTERSNEARME = &H3D
CSIDL_FLAG_PER_USER_INIT = &H800
CSIDL_FLAG_NO_ALIAS = &H1000
CSIDL_FLAG_DONT_VERIFY = &H4000
CSIDL_FLAG_CREATE = &H8000
CSIDL_FLAG_MASK = &HFF00
End Enum
CSIDL_DESKTOP = &H0
CSIDL_INTERNET = &H1
CSIDL_PROGRAMS = &H2
CSIDL_CONTROLS = &H3
CSIDL_PRINTERS = &H4
CSIDL_PERSONAL = &H5
CSIDL_FAVORITES = &H6
CSIDL_STARTUP = &H7
CSIDL_RECENT = &H8
CSIDL_SENDTO = &H9
CSIDL_BITBUCKET = &HA
CSIDL_STARTMENU = &HB
CSIDL_MYDOCUMENTS = &HC
CSIDL_MYMUSIC = &HD
CSIDL_MYVIDEO = &HE
CSIDL_DESKTOPDIRECTORY = &H10
CSIDL_DRIVES = &H11
CSIDL_NETWORK = &H12
CSIDL_NETHOOD = &H13
CSIDL_FONTS = &H14
CSIDL_TEMPLATES = &H15
CSIDL_COMMON_STARTMENU = &H16
CSIDL_COMMON_PROGRAMS = &H17
CSIDL_COMMON_STARTUP = &H18
CSIDL_COMMON_DESKTOPDIRECTORY = &H19
CSIDL_APPDATA = &H1A
CSIDL_PRINTHOOD = &H1B
CSIDL_LOCAL_APPDATA = &H1C
CSIDL_ALTSTARTUP = &H1D
CSIDL_COMMON_ALTSTARTUP = &H1E
CSIDL_COMMON_FAVORITES = &H1F
CSIDL_INTERNET_CACHE = &H20
CSIDL_COOKIES = &H21
CSIDL_HISTORY = &H22
CSIDL_COMMON_APPDATA = &H23
CSIDL_WINDOWS = &H24
CSIDL_SYSTEM = &H25
CSIDL_PROGRAM_FILES = &H26
CSIDL_MYPICTURES = &H27
CSIDL_PROFILE = &H28
CSIDL_SYSTEMX86 = &H29
CSIDL_PROGRAM_FILESX86 = &H2A
CSIDL_PROGRAM_FILES_COMMON = &H2B
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
CSIDL_COMMON_TEMPLATES = &H2D
CSIDL_COMMON_DOCUMENTS = &H2E
CSIDL_COMMON_ADMINTOOLS = &H2F
CSIDL_ADMINTOOLS = &H30
CSIDL_CONNECTIONS = &H31
CSIDL_COMMON_MUSIC = &H35
CSIDL_COMMON_PICTURES = &H36
CSIDL_COMMON_VIDEO = &H37
CSIDL_RESOURCES = &H38
CSIDL_RESOURCES_LOCALIZED = &H39
CSIDL_COMMON_OEM_LINKS = &H3A
CSIDL_CDBURN_AREA = &H3B
CSIDL_COMPUTERSNEARME = &H3D
CSIDL_FLAG_PER_USER_INIT = &H800
CSIDL_FLAG_NO_ALIAS = &H1000
CSIDL_FLAG_DONT_VERIFY = &H4000
CSIDL_FLAG_CREATE = &H8000
CSIDL_FLAG_MASK = &HFF00
End Enum
发表评论 - 不要忘了输入验证码哦! |