怎样用VB获得系统路径?

wmouse 2001-12-17 02:26:38
我试了两个API:
GetSystemDirectory
GetWindowsDirectory
好像不能用(抑或是我不会使8-P),恳请帮助。
...全文
106 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wmouse 2001-12-17
  • 打赏
  • 举报
回复
可惜我这本书太浅了,我这点知识还是看别人程序看来的,本来我的VC就半生不熟,现在又不得不用VB,多谢大伙关照,给分。
pp616 2001-12-17
  • 打赏
  • 举报
回复
呵呵。应该先看书啊。
DeityFox 2001-12-17
  • 打赏
  • 举报
回复
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Sub Form_Load()
'作者:蔡渭铭
'E-Mail: daniel_0571@263.net
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'获得系统路径
Ret = GetSystemDirectory(sSave, 255)
'以去掉没用的空串(chr(0))
sSave = Left$(sSave, Ret)
'显示路径
MsgBox "Windows System directory: " + sSave
End Sub
wmouse 2001-12-17
  • 打赏
  • 举报
回复
小弟刚用VB,还请问这个模块怎么加?
lioneye 2001-12-17
  • 打赏
  • 举报
回复
应该能用,不过,你用之前要定义存放的String的长度,所以,在调用API后,要将String里的路径再取一次,以去掉没用的空串。

Dim WinPath as String
Dim Pos as Integer

WinPath = String(80, "#")
Call GetWindowsDirectory(WinPath, 79)
Pos = InStr(WinPath, "#")
WinPath = Left(WinPath, Pos - 2)
liu_student_wei 2001-12-17
  • 打赏
  • 举报
回复
添加一模块,声明getsystemdirectory
在你需要的程序上,编写
Dim sysstr As String
sysstr = String(255, vbNullChar)
GetSystemDirectory sysstr, len(sysstr)

7,763

社区成员

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

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