我要在我的程序中往系统文件夹下的system文件夹下写入一个文件,如何才能知道不同的操作系统的系统文件是什么文件夹,在哪个盘符下。如:C:/windows d:/winnt d:/winnows

解决方案 »

  1.   

    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 Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
            (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Sub Command1_Click()
    Dim WinPath As String, SysPath As String
    Dim tempPath As String
    Dim len5 As Long
    '取得Windows 的目录
    WinPath = String(255, 0)
    len5 = GetWindowsDirectory(WinPath, 256)
    WinPath = Left(WinPath, InStr(1, WinPath, Chr(0)) - 1)
    Debug.Print "Window Path = "; WinPath'取得Windows System的目录
    SysPath = String(255, 0)
    len5 = GetSystemDirectory(SysPath, 256)
    SysPath = Left(SysPath, InStr(1, SysPath, Chr(0)) - 1)
    Debug.Print "System Path : "; SysPath'取得Temp的Directory
    tempPath = String(255, 0)
    len5 = GetTempPath(256, tempPath)
    tempPath = Left(tempPath, len5)
    Debug.Print "TEMP Path :"; tempPath
    End Sub
      

  2.   

    MsgBox Environ("WINDIR")
    这样可以简单的取得系统所在目录要得到系统文件夹路径要用API,如楼上
      

  3.   

    Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
        (ByVal lpBuffer As String, ByVal nSize As Long) As LongDim Junk As Long
    Dim WinSysDir As StringWinSysDir = Space(255)
    Junk = GetSystemDirectory(WinSysDir, 255)
    WinSysDir = Left(WinSysDir, InStr(WinSysDir, Chr(0)) - 1) '获取系统目录
      

  4.   

    这个用FSO就可以
    Dim fso
    Set fso = CreateObject("scripting.filesystemobject")
    MsgBox fso.GetSpecialFolder(0)
    MsgBox fso.GetSpecialFolder(1)
    Set fso = Nothing
      

  5.   

    Public Function SystemPath() As String
    Dim buf As String, msg As String, idx As Integer, SysPath As String
    idx = 1
    Do
    buf = Environ(idx)
    msg = msg & buf & vbCrLfIf StrComp(Left(buf, 10), "systemroot", vbTextCompare) = 0 Then
        SysPath = Mid(buf, 12)
        SysPath = Replace(SysPath, "/", "\")
        If Right(msg, 1) <> "\" Then SysPath = SysPath & "\"
        Exit Do
    End If
    idx = idx + 1
    Loop Until buf = ""If SysPath = "" Then
        MsgBox "程序无法得到系统目录,请和程序员联系。"
    End IfSystemPath = SysPath
    End Function