I need to extract the volume serial number from a hard disk, how can this be done?
Are there unique keys in the registry that I can use? (They must be unique for each machine)
Private Function GetSerialNum(ByVal DriveName As String) As Long
Dim loFSO As FileSystemObject
Dim loDrive As Drive
Set loFSO = New FileSystemObject
Set loDrive = loFSO.GetDrive(DriveName)
If loDrive.IsReady Then
GetSerialNum = loDrive.SerialNumber
Else
GetSerialNum = 0
End If
Set loFSO = Nothing
End Function
Private Declare Function GetVolumeInformation Lib "kernel32.dll" 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
Or otherwise you can us API:
(in that case you can get even more information as you can see)
Private Function GetSerialNum(DriveName As String) As Long
Dim lsVolumeName As String
Dim liSerialNum As Long
Dim lsSerNumStr As String
Dim liMaxCompLength As Long
Dim liFileSysFlags As Long
Dim lsFileSysName As String
Dim liRetval As Long
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.