Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Files Directories Drives Code Examples

Getting disk serial and freespace

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
Getting disk serial and freespace ' place in the declaration section of a bas file (global module) Private Declare Function GetVolumeInformation Lib "kernel32" _ alias "GetVolumeInformationA" _ (ByVal lpRootPathName As String, _ ByVal lpVolumeNameBuffer As String, _ ByVal nVolumeNameSize As Long, _ lpVolumeSerialNumber As Long, _ lpMaximumComponentLength As Long, _ lpfileSystemFlags As Long, _ ByVal lpFileSystemNameBuffer As String, _ ByVal nFileSystemNameSize 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 ' new public function, place in a bas file as well (global module) Public Function GetDriveInfo(filePath As String) As String Dim lpVolumeNameBuffer As String Dim nVolumeNameSize As String Dim lpVolumeSerialNumber As Long Dim lpMaximumComponentLength As Long Dim lpfileSystemFlags As Long Dim lpFileSystemNameBuffer As String Dim nFileSystemNameSize As Long Dim lpSectorsPerCluster As Long Dim lpBytesPerSector As Long Dim lpNumberOfFreeClusters As Long Dim lpTotalNumberOfClusters As Long Dim rtval As Long lpVolumeNameBuffer = Space(255) nVolumeNameSize = 256 lpFileSystemNameBuffer = Space(255) nFileSystemNameSize = 256 rtval = GetVolumeInformation(filePath, _ lpVolumeNameBuffer, _ nVolumeNameSize, _ lpVolumeSerialNumber, _ lpMaximumComponentLength, _ lpfileSystemFlags, _ lpFileSystemNameBuffer, _ nFileSystemNameSize) rtval = GetDiskFreeSpace(filePath, _ lpSectorsPerCluster, _ lpBytesPerSector, _ lpNumberOfFreeClusters, _ lpTotalNumberOfClusters) GetDriveInfo = "Volume Serial Number: " & lpVolumeSerialNumber & Chr(13) & Chr(10) & _ "Volume Size In Bytes: " & lpTotalNumberOfClusters * lpSectorsPerCluster * lpBytesPerSector & " bytes" & Chr(13) & Chr(10) & _ "Volume Free Space In Bytes: " & lpNumberOfFreeClusters * lpSectorsPerCluster * lpBytesPerSector & " bytes" End Function Return