先引用,菜单 -> 工程 -> 引用 -> micsoft scripting runtimeDim tCD As Scripting.Drive
Dim tMS As New Scripting.FileSystemObject
For Each tCD In tMS.Drives
    If tCD.DriveType = Fixed Then
        Debug.Print tCD.TotalSize
    End If
Next

解决方案 »

  1.   

    使用Api函数:GetDiskFreeSpace【VB声明】
      Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long【别名】
      GetDiskFreeSpaceA【说明】
      获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量 【返回值】
      Long,非零表示成功,零表示失败。会设置GetLastError 【备注】
      在采用FAT16格式的windows95系统中,如一个驱动器(分区)的容量超过了2GB,则不应使用这个函数。此时,这个函数能识别的最大分区容量只有2GB【参数表】
      lpRootPathName -  String,不包括卷名的一个磁盘根路径  lpSectorsPerCluster -  Long,用于装载一个簇内扇区数的变量  lpBytesPerSector -  Long,用于装载一个扇区内字节数的变量  lpNumberOfFreeClusters -  Long,用于装载磁盘上剩余簇数的变量  lpTtoalNumberOfClusters -  Long,用于装载磁盘上总簇数的变量实例:
    'In general section
    Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As LongPrivate Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]    Dim Sectors as Long,Bytes as Long,FreeC as Long, TotalC as Long,Total as Long,Freeb as Long
        'Retrieve information about the C:    GetDiskFreeSpace "C:\", Sectors, Bytes, Freec, Totalc
        'Set graphic mode to persistent
        Me.AutoRedraw = True
        'Print the information to the form
        Me.Print " Path: C:\"
        Me.Print " Sectors per Cluster:" + Str$(Sector)
        Me.Print " Bytes per sector:" + Str$(Bytes)
        Me.Print " Number Of Free Clusters:" + Str$(Freec)
        Me.Print " Total Number Of Clusters:" + Str$(Totalc)
        Total = rTotalc& * rSector& * rBytes&
        Me.Print " Total number of bytes in path:" + Str$(Total)
        Freeb = rFreec& * rSector& * rBytes&
        Me.Print " Free bytes:" + Str$(Freeb)
    End sub