How to find hard disk serial number ?
If you want to get the hard drive serial number or computer unique number then use this function.
This is Visual Basic 6.0 Code to Get the Computer Hard Drive Serial Number.
‘Computer Unique No or hard drive serial number From Visual Basic
Private Declare Function GetVolumeInformation _ Lib "kernel32.dll" _ Alias "GetVolumeInformationA" _ (ByVal lpRootPathName As String, _ ByVal lpVolumeNameBuffer As String, _ ByVal nVolumeNameSize As Integer, _ lpVolumeSerialNumber As Long, _ lpMaximumComponentLength As Long, _ lpFileSystemFlags As Long, _ ByVal lpFileSystemNameBuffer As String, _ ByVal nFileSystemNameSize As Long) As Long
This Function will return serial number of a Drive
Public Function GetSerialNumber(DriveLetter As String) As String
Dim SerialNum As Long
Dim VolNameBuf As String
Dim FileSysNameBuf As String
Select Case Len(DriveLetter)
Case 1
If DriveLetter Like "[a-z]" Then
DriveLetter = Left$(DriveLetter, 1) & ":\"
Else
GetSerialNumber = "Error - Bad drive designation"
End If
Case 2
If LCase(DriveLetter) Like "[a-z]:" Then
DriveLetter = DriveLetter & "\"
Else
GetSerialNumber = "Error - Bad drive designation"
End If
Case 3
If LCase(DriveLetter) Like "[!a-z]:\" Then
GetSerialNumber = "Error - Bad drive designation"
End If
Case Else
GetSerialNumber = "Error - Bad drive designation"
End Select
If Len(GetSerialNumber) = 0 Then
VolNameBuf = String$(255, Chr$(0))
FileSysNameBuf = String$(255, Chr$(0))
GetVolumeInformation DriveLetter, VolNameBuf, _
Len(VolNameBuf), SerialNum, 0, 0, _
FileSysNameBuf, Len(FileSysNameBuf)
GetSerialNumber = Right$("00000000" & Hex$(SerialNum), 8)
End If
End Function
This is good for security purpose. some time if you want to run your EXE file on some computer only then this is the best way.
Filed under: Hard drive Serial Number Tagged: | Computer unique number, Get Computer unique number form VB6, get drive serial number, getdrive serial number, Hard disk serial number, How to find Harddisk SerialNumber, software security, VB tips, VB Tricks, Visual Basic, Visual basic code, Visual Basic Tips









Its not that hard.. I think I can do that..
Thanks Raghu for sharing this..
Yes it is simple form VB you can use GetSerialNumber function to get HD serial number

Raghu