Private Declare Function GetWindowsDirectory Lib "Kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Function GetWinPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(260, 0)
lngResult = GetWindowsDirectory(strFolder, 260)
If lngResult <> 0 Then
GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1)
Else
GetWinPath = ""
End If
End Function
'GetWinPath()得知就是你要的东东
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim Path As String, strSave As String
strSave = String(200, Chr$(0))
Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave)))
MsgBox Path
End Sub
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" ( ByVal lpBuffer as String, ByVal nSize As Long)
以上函数得到的是Windows系统目录(SYSTEM)的完整路径,有了它,相信得到WINDOWS的完整路径就不困难了。
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
'Show the windows directory
MsgBox "Windows System directory: " + sSave
End Sub