'========================方法一========================
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function GetWinDir() As String
Dim sBuffer As String
Dim lSize As String
sBuffer = String(255, 0)
lSize = GetWindowsDirectory(sBuffer, Len(sBuffer))
sBuffer = Left(sBuffer, lSize) & "\"
GetWinDir = sBuffer
End Function
Public Function GetSysDir() As String
Dim sBuffer As String
Dim lSize As String
sBuffer = String(255, 0)
lSize = GetSystemDirectory(sBuffer, Len(sBuffer))
sBuffer = Left(sBuffer, lSize) & "\"
GetSysDir = sBuffer
End Function
'-------------------------------------------------以上代码放模块里
Private Sub Command1_Click()
Text1.Text = GetWinDir() '-------------------------windows路径
Text2.Text = GetSysDir() '-------------------------system路径
End Sub
'========================方法二========================
Private Sub Command1_Click()
Text1.Text = Environ("windir") 'windows路径
Text2.Text = Environ("windir") + "\system32\" 'system路径
End Sub