高手们,帮帮忙!如何得到当前用户目录,在线等待,马上结帐!尽管分数不是很多,不过我已经尽力啦:)

qq_net 2003-12-24 03:25:28
我要得到如下目录:
======================================
如果系统装在C盘,并且当前用户是Administrator用户,则取出如下路径
"C:\Documents and Settings\Administrator\桌面"
======================================
如果系统装在D盘,并且当前用户是Administrator用户,则取出如下路径
"D:\Documents and Settings\Administrator\桌面"
======================================
如果系统装在D盘,并且当前用户是user用户,则取出如下路径
"D:\Documents and Settings\user\桌面"

======================================
还请高手们不吝赐教!!!!!!!!!!!!!!!!!
...全文
36 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinliangyu 2004-01-05
  • 打赏
  • 举报
回复
注册表项Hkey_local_machine\software\microsoft\winodws\currentversion\explorer\shell folders\desktop 的值就是人所要的
99175776 2003-12-29
  • 打赏
  • 举报
回复
最简单的办法就是你把 .exe文件安装在桌面,用app.path 就可以了。好久不写VB 了懂我的命令语言吧!
88391788 2003-12-29
  • 打赏
  • 举报
回复
mark
可以使Environ("userprofile")+"\桌面"就可以了!
qq_net 2003-12-25
  • 打赏
  • 举报
回复
非常感谢以上各位
pasl 2003-12-24
  • 打赏
  • 举报
回复
可以使Environ("userprofile")+"\桌面"就可以了!
mmclg 2003-12-24
  • 打赏
  • 举报
回复
楼主好象不是这个意思
liuxum 2003-12-24
  • 打赏
  • 举报
回复
用API函数:
在模块中:
******************************
Declare Function SHGetSpecialFolderLocation Lib "shell32" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, ppidl As Long) As Long


Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidl As Long, ByVal pszPath As String) As Long


Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)

Public Function pbGetSpecialFolderPath(ByVal avFolderID As Long) As String

Dim lvLongRet As Long
Dim lvPidlFolder As Long
Dim lvStrBuf As String
Dim lvHWnd As Long
Const lcMAX_PATH As Integer = 260

lvHWnd = 0
lvLongRet = SHGetSpecialFolderLocation(lvHWnd, avFolderID, lvPidlFolder)

If lvLongRet >= 0 Then
lvStrBuf = String$(lcMAX_PATH, vbNullChar)
If SHGetPathFromIDList(lvPidlFolder, lvStrBuf) <> 0 Then
lvStrBuf = pvEditBuf(lvStrBuf)

End If

CoTaskMemFree lvPidlFolder
pbGetSpecialFolderPath = lvStrBuf
End If

End Function

Private Function pvEditBuf(ByVal avBuf As String) As String

Dim i As Long

i = InStr(avBuf, vbNullChar)
If i <> 0 Then
pvEditBuf = Left$(avBuf, i - 1)
Else
pvEditBuf = avBuf
End If

End Function
******************************
可以这样使用:
dim strPath as string
strPath= pbGetSpecialFolderPath(&H10)
msgbox strPath
jhzhou882 2003-12-24
  • 打赏
  • 举报
回复
可以使用Environ("windir")获得Windows目录。
也可以调用API函数,使用GetWindowsDirectory可以获得Windows目录,使用GetSystemDirectory可以获得系统目录。
GetWindowsDirectory声明:
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

GetSystemDirectory函数声明:
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA"(Byval lpBuffer as Long,Byval nSize as Long) As Long

要使用这些函数,必须先定义好一个非空的字符串,将它传递给lpBuffer参数,而将其长度传递给nSize参数。实现过程如下(WinPath为Windows的所在目录, SysPath为 System的所在目录):
Dim s as String *80
Dim Length As Long
Dim WinPath As String
Dim SysPath AS String
Length=GetWindowsDirectory(s,Len(s))
WinPath=Left(s,Length)
Length=GetSystemDirectory(s,Len(s))
SysPath=Left(s,Length)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧