1.使用GetWindowsDirectory GetSystemDirectory windows api
楼上的baoaya(点头)能给出代码嘛,我是初学的,非常感谢
第一个问题: 如何找出 Windows 目录的正确路径?- -
有时候我们在程序中必须用到 Windows 的目录,以存取 Windows 目录下的文件,照理说,这应该是最简单的功能,前提是每个人在 Setup Windows 必须采用 Windows 的预设目录名称,也就是 C:\Windows,但是常常不是这样,有时候由於要使新旧版本共存,或者其他原因,有人会将 Windows 目录改成 c:\win95、c:\win98、Windows95 或 Windows98......若是程序中必须用到 Windows 目录,要找到正确的路径,做法如下:'在声明区中加入以下声明:Const MAX_PATH = 260Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPublic Function GetWinPath() Dim strFolder As String Dim lngResult As Long strFolder = String(MAX_PATH, 0) lngResult = GetWindowsDirectory(strFolder, MAX_PATH) If lngResult <> 0 Then GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1) Else GetWinPath = "" End If End Function'在程序中使用方法如下:Private Sub Command1_Click() Call MsgBox("您电脑中 Windows 目录的正确路径是: " & GetWinPath, vbInformation) End Sub
如何找出 Windows 目录的正确路径?- -
有时候我们在程序中必须用到 Windows 的目录,以存取 Windows 目录下的文件,照理说,这应该是最简单的功能,前提是每个人在 Setup Windows 必须采用 Windows 的预设目录名称,也就是 C:\Windows,但是常常不是这样,有时候由於要使新旧版本共存,或者其他原因,有人会将 Windows 目录改成 c:\win95、c:\win98、Windows95 或 Windows98......若是程序中必须用到 Windows 目录,要找到正确的路径,做法如下:'在声明区中加入以下声明:Const MAX_PATH = 260Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPublic Function GetWinPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetWindowsDirectory(strFolder, MAX_PATH)
If lngResult <> 0 Then
GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1)
Else
GetWinPath = ""
End If
End Function'在程序中使用方法如下:Private Sub Command1_Click()
Call MsgBox("您电脑中 Windows 目录的正确路径是: " & GetWinPath, vbInformation)
End Sub
其实VB自带的函数就可以解决这个问题.并且可以得到所有的系统环境变量
函数名字我忘记了./
看MSDN吧