小弟的电脑上装有双操作系统,我的问题是:
怎样用 VB 程序获得当前正在使用的 windows 系统被安装在哪个文件夹下
C:\windows\ 还是 D:\windows\ ?

解决方案 »

  1.   

    Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Longdim sysdir as string
    sysdir = string(vbnullchar,256)
    getsystemdirectory sysdir,256
      

  2.   

    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongDim S As String
    S = String(256, " ")
    GetWindowsDirectory S, 256
    MsgBox "Windows装在" & Left(S, 1) & "盘"
      

  3.   

    如以上朋友所说,用API就可以啦
      

  4.   

    小弟按大侠的指点建立了如下工程:Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongDim S As String
    S = String(256, " ")
    GetWindowsDirectory S, 256
    MsgBox "Windows装在" & Left(S, 1) & "盘"
    Private Sub Command1_Click()
    GetSystemDirectoryA
    End Sub想实现点击按钮 Command1 就弹出
    MsgBox "Windows装在" & Left(S, 1) & "盘"
    可是运行时却提示 S = String(256, " ") 出错 “编译错误:无效外部过程”
    恳请大侠再指点一下。
      

  5.   

    MsgBox "系统目录:" & VBA.Environ$("windir")
      

  6.   

    环境变量是可以删掉的
    set windir=所以标准方法是用GetWindowsDirectory
    至于那个问题,可能是由于VBA库出错。将String()改成VBA.String$()
      

  7.   

    ?????Dim S As String
    S = String(256, " ")
    GetWindowsDirectory S, 256
    MsgBox "Windows装在" & Left(S, 1) & "盘"
    Private Sub Command1_Click()
    GetSystemDirectoryA
    End Sub这段代码是在哪里的呀?应该是这样:Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Sub Command1_Click()  Dim S As String
      S = String(256, " ")
      GetWindowsDirectory S, 256
      MsgBox "Windows装在" & Left(S, 1) & "盘"End Sub