VB的绝对路径是什么?

如题所述

Option Explicit
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 sysdir As String
Dim chrlen As Long
Dim windir As String

' 获得system路径
sysdir = Space(max_path)
chrlen = GetSystemDirectory(sysdir, max_path)
If chrlen > max_path Then chrlen = GetSystemDirectory(sysdir, 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)

' 在窗体上显示system路径
Label1.Caption = "system的路径为: " & sysdir
' 在窗体上显示windows路径
Label2.Caption = "windows的路径为: " & windir
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答