Link to home
Start Free TrialLog in
Avatar of majestic
majestic

asked on

Hard Drive Serial Number

How do you go about getting the hard drive serial number in Visual Basic.
ASKER CERTIFIED SOLUTION
Avatar of bin_huwairib
bin_huwairib

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dalin
Dalin

Option ExplicitPrivate 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 Sub cmdTest_Click()
   Dim iSerialNum As Long   Dim sVolumeLabel As String
   Dim sVolumeType As String   Dim iRetVal As Long   sVolumeLabel = Space(255)
   sVolumeType = Space(255)   iRetVal = GetVolumeInformation("f:\", _
      sVolumeLabel, Len(sVolumeLabel), _      iSerialNum, _      0, 0, _
      sVolumeType, Len(sVolumeType))  
   MsgBox "Disk Serial Number: " & iSerialNum & vbCrLf _
      & "Volume Type: " & Left$(sVolumeType, InStr(sVolumeType, Chr$(0)) - 1) & vbCrLf _
      & "Volume Label: " & Left$(sVolumeLabel, InStr(sVolumeLabel, Chr$(0)) - 1)
End Sub