无地自容的故事:请教一个VB的简单问题!

来源:百度文库 编辑:高考问答 时间:2024/03/29 17:39:22
如何通过VB代码获得系统的Windows 根目录,例如在WIN2000运行的时候就让TEXT1.TEXT变成"C:\WINNT" 在XP运行的时候就变成 "C:\windows"

请各位高手教教我~~~谢谢!

用GetWindowsDirectory函数可以寻找Windows目录
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String,ByVal nSize As Long) As Long

Private Sub Form_load
Dim strBuffer As String *1024
retVal=GetWindowsDirectory(strBuffer,1024)
label1.caption="Windows directory:"&strBuffer

are you know?

''先声明一个函数..

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long

''Public Function GetWindowsPath() As String
Dim p As String * 80
Dim length As Long
Dim path As String

length = GetWindowsDirectory(p, Len(p))
path = Left(p, length)

GetWindowsPath = path
End Function

''获取
Private Sub Command1_Click()
text1.text = GetWindowsPath
End Sub

懂了没.我调试过的.