Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByVal lpFreeBytesAvailable As Long, ByVal lpTotalNumberOfBytes As Long, ByVal lpTotalNumberOfFreeBytes As Long) As Long
'注释:由于在 MSDN 中提到此函数的 lpFreeBytesAvailable 和 lpTotalNumberOfBytes 参数在Windows Me/98/95中不能为Null,所以就有了下面的 VarPtr(CCur(0))。
Public Function GetFreeSpace(ByVal Path As String) As Variant
Dim vSize As Currency
If GetDiskFreeSpaceEx(Path, VarPtr(vSize), VarPtr(CCur(0)), 0) = 0 Then
Err.Raise 5
Else
GetFreeSpace = CDec(vSize) * 10000 '这里搞错了:P
End If
End Function
Public Function GetTotalSpace(ByVal Path As String) As Variant
Dim vSize As Currency
If GetDiskFreeSpaceEx(Path, VarPtr(CCur(0)), VarPtr(vSize), 0) = 0 Then
Err.Raise 5
Else
GetTotalSpace = CDec(vSize) * 10000 '这里搞错了:P
End If
End Function
Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByVal lpFreeBytesAvailable As Long, ByVal lpTotalNumberOfBytes As Long, ByVal lpTotalNumberOfFreeBytes As Long) As Long
'注释:由于在 MSDN 中提到此函数的 lpFreeBytesAvailable 和 lpTotalNumberOfBytes 参数在Windows Me/98/95中不能为Null,所以就有了下面的 VarPtr(CCur(0))。
Public Function GetFreeSpace(ByVal Path As String) As Variant
Dim vSize As Currency
If GetDiskFreeSpaceEx(Path, VarPtr(vSize), VarPtr(CCur(0)), 0) = 0 Then
Err.Raise 5
Else
GetFreeSpace = CDec(vSize * 10000)
End If
End Function
Public Function GetTotalSpace(ByVal Path As String) As Variant
Dim vSize As Currency
If GetDiskFreeSpaceEx(Path, VarPtr(CCur(0)), VarPtr(vSize), 0) = 0 Then
Err.Raise 5
Else
GetTotalSpace = CDec(vSize * 10000)
End If
End Function
Private Sub Command4_Click()
Dim strComputer As String
Dim objWMIService As Object
Dim colProcessList
Dim objProcess As Object
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("select * FROM Win32_logicaldisk")
For Each objProcess In colProcessList
enum1 = enum1 + objProcess.Name + ", "
enum1 = enum1 + CStr(objProcess.drivetype) + ","
enum1 = enum1 + CStr(objProcess.Size) + ", "
enum1 = enum1 + CStr(objProcess.freespace) + ","
enum1 = enum1 + CStr(objProcess.Description) + ","
enum1 = enum1 + Chr(13) + Chr(10)
Next
Debug.Print enum1
End Sub
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 Long
'Path = "c:\" 指定Volume 代号, 如: c:\ d:\ e:\
Public Function GetFreeSpace(Byval Path as String) as Long
Dim aa As Long
Dim Path As String
Dim SecPerClust As Long
Dim BytePerSec As Long, FreeClust As Long, totClust As Long
Path = "c:\" '指定Volume 代号, 如: c:\ d:\ e:\
aa = GetDiskFreeSpace(Path, SecPerClust, BytePerSec, FreeClust, totClust)
GetFreeSpace = SecPerClust * BytePerSec * FreeClust
End Function
'Path = "c:\" 指定Volume 代号, 如: c:\ d:\ e:\
Public Function GetTotalSpace(Byval Path as String) as Long
Dim aa As Long
Dim Path As String
Dim SecPerClust As Long
Dim BytePerSec As Long, FreeClust As Long, totClust As Long
aa = GetDiskFreeSpace(Path, SecPerClust, BytePerSec, FreeClust, totClust)
GetTotalSpace = SecPerClust * BytePerSec * totClust