如何获得COOKIES文件夹目录

ada8593 2006-01-22 02:01:32
请问各位,我想获得COOKIES文件夹的目录该如何获得,因为不同的操作系统该文件夹所在目录都不同,我想有没有一个方法能自动获取该文件目录啊
我从论坛上搜索了一个方法能自动获取SYSTEM文件夹的目录,不知道是否能改造成我需要的代码,请各位出个主意,谢谢

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
'Show the windows directory
MsgBox "Windows System directory: " + sSave
End Sub
...全文
116 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ada8593 2006-01-24
谢谢rainstormmaster,成功了,分数比较少,大家都很热心,我就都给点,论坛没有追加分数的功能,要不多给点大家,呵呵。
回复
sakurako 2006-01-23
加括号
l = GetEnvironmentVariable ("USERPROFILE", s, 1024)
不是.NET专用的
回复
ada8593 2006-01-23
我用了sakurako的方法,双击窗体,把代码覆盖进去,结果
l = GetEnvironmentVariable "USERPROFILE", s, 1024
这一行显示红色,显示编译错误,请问该怎么修改,你的代码是。NET用的吗,我是初学,谢谢楼上各位,请继续指点
回复
rainstormmaster 2006-01-23
什么系统?另外,你的权限够吗?是以管理员登录的吗?

出现这个错误的可能原因是
Set mshell = CreateObject("shell.Application")
这一句中shell.Application这个ProgId在你的系统中是其它的名字,这样:

先添加对:Microsoft Shell Controls And Automation的引用(对应文件SHELL32.dll)
Private Sub Command1_Click()
Dim mshell As New Shell
Dim mfolder As Folder
Set mshell = CreateObject("shell.Application")
Set mfolder = mshell.NameSpace(33)
MsgBox mfolder.Self.Path
Set mfolder = Nothing
Set mshell = Nothing
End Sub
回复
ada8593 2006-01-23
试了rainstormmaster的方法,窗体上加一按牛,把代码覆盖进去,运行出现:实时错误429,ACTIVEX部件不能创建对象,请指点,谢谢
回复
rainstormmaster 2006-01-23
这样也可以:
Private Sub Command1_Click()
Dim mshell As Object
Dim mfolder As Object
Set mshell = CreateObject("shell.Application")
Set mfolder = mshell.NameSpace(33)
MsgBox mfolder.Self.Path
Set mfolder = Nothing
Set mshell = Nothing
End Sub

回复
zyl910 2006-01-23
http://vbnet.mvps.org/index.html?code/browse/csidl.htm
回复
ada8593 2006-01-23
程序通过运行了,但没有结果显示出来啊,我把命令按钮1设置了Print GetCookDir ,但屏幕上没有什么输出,小弟初学,请各位保持耐心,呵呵

Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Function GetCookiesDir() As String
Dim s As String * 1024
Dim l As Long
l = GetEnvironmentVariable("USERPROFILE", s, 1024)
GetCookDir = Left(s, l) & "\" & "Cookies"
End Function

Private Sub Command1_Click()
Print GetCookDir '我在这里加了个输出命令
End Sub
回复
zyl910 2006-01-23
Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
回复
ada8593 2006-01-23
再次运行,第一行出现错误
编译错误:常数,固定长度字符串,数组,用户定义类型以及DECLARE不允许作为对象摸块的PUBLIC成员
我是把下面的代码直接复制到双击窗体出现的代码输入中去的
Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Function GetCookiesDir() as String
Dim s as String * 1024
Dim l as Long
l = GetEnvironmentVariable ("USERPROFILE", s, 1024)
GetCookDir = Left(s, l) & "\" & "Cookies"
End Function
请指点,谢谢
回复
sakurako 2006-01-22
Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Function GetCookiesDir() as String
Dim s as String * 1024
Dim l as Long
l = GetEnvironmentVariable "USERPROFILE", s, 1024
GetCookDir = Left(s, l) & "\" & "Cookies"
End Function
回复
zyl910 2006-01-22
SHGetSpecialFolderPath


WINSHELLAPI HRESULT WINAPI SHGetSpecialFolderPath(
HWND hwndOwner,
LPTSTR lpszPath,
int nFolder,
BOOL fCreate
);

Retrieves the path of a special folder.

Returns NOERROR if successful, or an OLE-defined error result otherwise.
hwndOwner
Handle to the owner window the client should specify if it displays a dialog box or message box.
lpszPath
Address of a character buffer that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
nFolder
Value specifying the folder for which to retrieve the location. This can be one of the nFolder values described in SHGetSpecialFolderLocation. This argument must specify a real folder and not a virtual folder. If a virtual folder is specified, this function will fail.
fCreate
Indicates if 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.








CSIDL_ALTSTARTUP File system directory that corresponds to the user's nonlocalized Startup program group.
CSIDL_APPDATA File system directory that serves as a common repository for application-specific data.
CSIDL_BITBUCKET File system directory containing file objects in the user's Recycle Bin. The location of this directory is not in the registry; it is marked with the hidden and system attributes to prevent the user from moving or deleting it.
CSIDL_COMMON_ALTSTARTUP File system directory that corresponds to the nonlocalized Startup program group for all users.
CSIDL_COMMON_DESKTOPDIRECTORY File system directory that contains files and folders that appear on the desktop for all users.
CSIDL_COMMON_FAVORITES File system directory that serves as a common repository for all users' favorite items.
CSIDL_COMMON_PROGRAMS File system directory that contains the directories for the common program groups that appear on the Start menu for all users.
CSIDL_COMMON_STARTMENU File system directory that contains the programs and folders that appear on the Start menu for all users.
CSIDL_COMMON_STARTUP File system directory that contains the programs that appear in the Startup folder for all users.
CSIDL_CONTROLS Virtual folder containing icons for the Control Panel applications.
CSIDL_COOKIES File system directory that serves as a common repository for Internet cookies.
CSIDL_DESKTOP Windows Desktop—virtual folder at the root of the namespace.
CSIDL_DESKTOPDIRECTORY File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).
CSIDL_DRIVES My Computer—virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FAVORITES File system directory that serves as a common repository for the user's favorite items.
CSIDL_FONTS Virtual folder containing fonts.
CSIDL_HISTORY File system directory that serves as a common repository for Internet history items.
CSIDL_INTERNET Virtual folder representing the Internet.
CSIDL_INTERNET_CACHE File system directory that serves as a common repository for temporary Internet files.
CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood.
CSIDL_NETWORK Network Neighborhood Folder—virtual folder representing the top level of the network hierarchy.
CSIDL_PERSONAL File system directory that serves as a common repository for documents.
CSIDL_PRINTERS Virtual folder containing installed printers.
CSIDL_PRINTHOOD File system directory that serves as a common repository for printer links.
CSIDL_PROGRAMS File system directory that contains the user's program groups (which are also file system directories).
CSIDL_RECENT File system directory that contains the user's most recently used documents.
CSIDL_SENDTO File system directory that contains Send To menu items.
CSIDL_STARTMENU File system directory containing Start menu items.
CSIDL_STARTUP File system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT or starts Windows 95.
CSIDL_TEMPLATES File system directory that serves as a common repository for document templates.
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告