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

解决方案 »

  1.   

    Dim EnvString, Indx, Msg, PathLen   ' 声明变量。
    Indx = 1   ' 设置索引值的初值为 1。
    Do
       EnvString = Environ(Indx)   ' 取得环境变量。
       If Left(EnvString, 5) = "PATH=" Then   ' 检查 PATH 项。
          PathLen = Len(Environ("PATH"))   ' 取得长度。
          Msg = "PATH entry = " & Indx & " and length = " & PathLen
          Exit Do
       Else
          Indx = Indx + 1   ' 不是 PATH 项,
       End If   ' 则跳过此项,继续检查下一项。
    Loop Until EnvString = ""
    If PathLen > 0 Then
       MsgBox Msg   ' 显示消息。
    Else
       MsgBox "No PATH environment variable exists."
    End If想找系统目录用windir(注意是小写)代替上面的PATH就行了
      

  2.   

    GetSystemDirectory可以获得你的系统目录
    Dim a As String
      Dim b As String * 256
      a = GetSystemDirectory(b, 256)
    则b内表示的就是系统目录
      

  3.   

    我用sFilePath = Trim(sFilePath) & "\" & "yb.ini"来取yb.ini文件,怎么sFilePath还是原来的目录,而没有加文件的名??
      

  4.   

    fraser01(王晓栋),有什么办法吗?
      

  5.   

    sFilePath后有好多空白去不掉,帮忙!!!
      

  6.   

    Private Sub Command1_Click()
    Dim spath As String
    Dim a As Long
    spath = Space(256)
    a = GetSystemDirectory(spath, 256) 'a为返回系统路径长度
    spath = Left(spath, a)
    spath = spath & "\yb.ini"
    Text1.Text = spath
    End Sub