Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract vol serial number from a hard drive? 2

Status
Not open for further replies.

mage

Programmer
Jul 17, 2001
7
ZA
Hi,

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)
 
It's easy using FileSystemObject:

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

lsVolumeName = Space$(256)
lsFileSysName = Space$(256)

liRetval = GetVolumeInformation(DriveName, lsVolumeName, 256, liSerialNum, liMaxCompLength, liFileSysFlags, lsFileSysName, 256)

GetSerialNum = liSerialNum
End Function

Remedy
 
Hey remedy,
Thanks for the help, will try to fit this into my prog.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top