ITPub博客

首页 > 应用开发 > IT综合 > 取系统路径

取系统路径

原创 IT综合 作者:qq34352631 时间:2007-10-25 11:52:01 0 删除 编辑

取系统路径

[@more@]Option Explicit
Dim ret As String
Dim jj As String
Dim winsys As String
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const max_path = 260
'Private Const max_path1 = 261


Private Sub Command1_Click()
Dim ssave As String
ssave = Space(255)
ret = GetSystemDirectory(ssave, 255)
jj = Len(Trim(ssave))
winsys = Trim(Mid$(ssave, 1, jj - 1))
MsgBox winsys
End Sub

Private Sub Command2_Click()
Dim sysdir As String
Dim chrlen As Long
Dim windir As String

'sysdir变量要给足了空格
sysdir = Space(max_path)
chrlen = GetSystemDirectory(sysdir, max_path) '将系统路径保存在字符串sysdir中,字符串最大长度为260


If chrlen > max_path Then chrlen = GetSystemDirectory(sysdir, chrlen)

'chrlen是返回字符串的实际长度
sysdir = Left(sysdir, chrlen)

'-------------------------------------------------
'取windows路径
windir = Space(max_path)
chrlen = GetWindowsDirectory(windir, max_path)
If chrlen > max_path Then chrlen = GetWindowsDirectory(windir, chrlen)
windir = Left(windir, chrlen)
MsgBox "system的路径为: " & sysdir
MsgBox "windows的路径为: " & windir
MsgBox "当前系统的盘符为:" & Left(windir, 1)
End Sub

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7646028/viewspace-978528/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论
  • 博文量
    12
  • 访问量
    14994