因为xp目录为c:\windows\system32
而2000或NT目录为:c:\winnt\system32
现在在system32下加入了自己的dll,使用之前想先判断一下dll文件是否存在,现在是想要是有函数可以直接取得system32目录的话,那么就可以直接用dir函数来判断了。
请问有没有我想要的这种函数或有没有更好的方法来作判断?

解决方案 »

  1.   

    GetSystemDirectory VB声明 
    Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long 
    说明 
    这个函数能取得Windows系统目录(System目录)的完整路径名。在这个目录中,包含了所有必要的系统文件。根据微软的标准,其他定制控件和一些共享组件也可放到这个目录。通常应避免在这个目录里创建文件。在网络环境中,往往需要管理员权限才可对这个目录进行写操作 
    返回值 
    Long,装载到lpBuffer缓冲区的字符数量。如lpBuffer不够大,不能容下文件名,则返回要求的缓冲区长度 
    参数表 
    参数 类型及说明 
    lpBuffer String,用于装载系统目录路径名的一个字串缓冲区。它应事先初始化成nSize+1个字符的长度。通常至少要为这个缓冲区分配MAX_PATH个字符的长度 
    nSize Long,lpBuffer字串的最大长度 
      

  2.   

    28.获得系统文件夹的路径
    Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
     "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Sub Command1_Click()
       Dim syspath As String
       Dim len5 As Long
       syspath = String(255, 0)
       len5 = GetSystemDirectory(syspath, 256)
       syspath = Left(syspath, InStr(1, syspath, Chr(0)) - 1)
       Debug.Print "System Path : "; syspath
    End Sub
      

  3.   

    Option ExplicitPublic Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPublic Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongPublic Function WinDir() As String
        Dim S As String
        Dim Z As Long
        Dim R As Long
        S = Space(254)
        Z = Len(S)
        R = GetWindowsDirectory(S, Z)
        WinDir = Left(S, R)
        WinDir = WinDir & "\"
    End FunctionPublic Function SysDir() As String
        Dim S As String
        Dim Z As Long
        Dim R As Long
        S = Space(254)
        Z = Len(S)
        R = GetSystemDirectory(S, Z)
        SysDir = Left(S, R)
        SysDir = SysDir & "\"
    End FunctionPublic Function TempDir() As String
        Dim S As String
        Dim Z As Long
        Dim R As Long
        S = Space(254)
        Z = Len(S)
        R = GetTempPath(Z, S)
        TempDir = Left(S, R)
    End FunctionPublic Function UserName() As String
        Dim S As String
        Dim Z As Long
        Dim R As Long
        S = Space(254)
        Z = Len(S)
        R = GetUserName(S, Z)
        UserName = S
    End FunctionPublic Function ComputerName() As String
        Dim S As String
        Dim Z As Long
        Dim R As Long
        S = Space(254)
        Z = Len(S)
        R = GetComputerName(S, Z)
        ComputerName = S
    End Function
      

  4.   

    试一下这个MsgBox Environ("windir")
      

  5.   

    '试试这两个。
    Private Sub Form_Load()
    MsgBox Environ("systemroot")
    MsgBox Environ("systemroot") & "\system32"
    End Sub