在线等 如何取得操作系统的安装目录即取得XP系统中的C:/windows,2000系统中的C:/winnt,要是安装在D盘则XP系统中的D:/windows,2000系统中的D:/winnt

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function GetSystemDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long'// -System Path-
    private Property Get LocalSystemPath() As String
        On Error Resume Next
        LocalSystemPath = String$(256, Chr(0))
        If GetSystemDirectoryA(LocalSystemPath, 256) <> 0 Then LocalSystemPath = Left$(LocalSystemPath & Chr(0), InStr(LocalSystemPath & Chr(0), Chr(0)) - 1)
        Call Err.Clear
        DoEvents
    End Property
      

  2.   

    如果要取得Windows 的就换以下APIprivate Declare Function GetWindowsDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long'// -System Path-
    private Property Get LocalSystemPath() As String
        On Error Resume Next
        LocalSystemPath = String$(256, Chr(0))
        If GetWindowsDirectoryA (LocalSystemPath, 256) <> 0 Then LocalSystemPath = Left$(LocalSystemPath & Chr(0), InStr(LocalSystemPath & Chr(0), Chr(0)) - 1)
        Call Err.Clear
        DoEvents
    End Property
      

  3.   

    不知道怎么用啊?比如我单击Command1_Click() 让Label1.caption=取得的系统目录呢
      

  4.   

    Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    不知道怎么用啊?比如我单击Command1_Click() 让Label1.caption=取得的系统目录呢
      

  5.   

    Private Const MAX_PATH = 260
    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Function GetWinPath() '获取Windows目录
        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 FunctionPrivate sub command1_click()
        label1.caption=GetWinPath()
    end sub
      

  6.   

    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   
        
      Private   Sub   Command1_Click()   
              Dim   b   As   String   
              Dim   p   As   Integer   
              b   =   Space(260)   
              p   =   GetWindowsDirectory(b,   Len(b))   
              WinPath   =   Left(b,   p)   
              Text1.Text   =   WinPath   
      End   Sub   
        
      Private   Sub   Command2_Click()   
              Dim   b   As   String   
              Dim   p   As   Integer   
              b   =   Space(260)   
              p   =   GetSystemDirectory(b,   Len(b))   
              WinSysPath   =   Left(b,   p)   
              text2.Text   =   WinSysPath   
      End   Sub   
        
      Private   Sub   Command3_Click()   
              End   
      End   Sub   
        
        
      注:请在窗体上加上两个文本框和三个按钮即可。