|
|
Free VB Projects
|
Get Windows & System directories, disk free space, serial number and other disk properties (using Windows API calls) |
Description:
This VB project retrieves such information as the
Windows and System directories, the disk free space (for the given drive letter), the disk or drive serial number,
the sectors per cluster, the bytes per sector and some other disk properties, using Windows API calls.
Keywords:
Windows directory, System directory, Disk serial
number,
Disk free space, Disk serial number, Drive serial number, Sectors per cluster,
Bytes per sector, Disk free clusters, Total number of clusters
'Declare Windows API functions
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 GetDiskFreeSpace Lib "kernel32" _
Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters _
As Long) As Long
Private Sub Form_Load()
'Retrieve the path of the Windows directory
Dim WinPath As String
'Create a string buffer
WinPath = String(145, Chr(0))
'Call GetWindowsDirectory API function
WinPath = Left(WinPath, GetWindowsDirectory(WinPath, _
Len(WinPath)))
'Retrieve the path of the Windows system directory
Dim SystemPath As String
'Create a string buffer
SystemPath = String(145, Chr(0))
'Call GetSystemDirectory API function
SystemPath = Left(SystemPath, GetSystemDirectory(SystemPath, _
Len(SystemPath)))
'Call the GetDiskFreeSpace API function to retrieve disk
'free space, sectors per cluster, bytes per sector, number
'of free clusters and total number of clusters
X& = GetDiskFreeSpace("c:\", b&, c&, d&, e&)
'Display the info
msg = "Windows directory is: " + WinPath & vbCrLf
msg = msg & "System directory is: " + SystemPath & _
vbCrLf & vbCrLf
msg = msg & "Drive Info for C:" & vbCrLf
msg = msg & "Sectors Per Cluster= " & b& & vbCrLf
msg = msg & "Bytes Per Sector= " & c& & vbCrLf
msg = msg & "Number Of Free Clusters= " & d& & vbCrLf
msg = msg & "Total Number Of Clusters= " & e& & vbCrLf
msg = msg & "Disk Free Space= " & Format$(b& * c& * d&, _
"###,###,###,###") & " Bytes" & vbCrLf
MsgBox msg
End
End Sub
Return to VB projects
|