Dxt-Cobra
09-14-2007, 09:05 AM
API to Get Hard Drive Serial Number
Use this code to get a hard drive, floppy, CD-ROM, ... serial number.
Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal pVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaxComponentLentgh As Long, _
lpFileSysyemFlags As Long, _
ByVal lpFileSystemBuffername As String, _
ByVal nFileSystemNameSize As Long) As Long
Public Function GetSerialNumber(ByVal sDrive As String) As Long
If Len(sDrive) Then
If InStr(sDrive, "\\") = 1 Then
'Make sure we end in backslash for UNC
If Right$(sDrive, 1) <> "\" Then
sDrive = sDrive & "\"
End If
Else
'If not UNC take first letter as drive
sDrive = Left$(sDrive, 1) & ":\"
End If
Else
'Use current drive
sDrive = vbNullString
End If
Call GetVolumeInformation(sDrive, vbNullString, 0, GetSerialNumber, ByVal 0&, _
ByVal 0&, vbNullString, 0)
End Function
Private Sub Command1_Click()
Dim sDrive As String
sDrive = InputBox("Enter drive for checking SN")
MsgBox Hex$(GetSerialNumber(sDrive))
End Sub
Use this code to get a hard drive, floppy, CD-ROM, ... serial number.
Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal pVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaxComponentLentgh As Long, _
lpFileSysyemFlags As Long, _
ByVal lpFileSystemBuffername As String, _
ByVal nFileSystemNameSize As Long) As Long
Public Function GetSerialNumber(ByVal sDrive As String) As Long
If Len(sDrive) Then
If InStr(sDrive, "\\") = 1 Then
'Make sure we end in backslash for UNC
If Right$(sDrive, 1) <> "\" Then
sDrive = sDrive & "\"
End If
Else
'If not UNC take first letter as drive
sDrive = Left$(sDrive, 1) & ":\"
End If
Else
'Use current drive
sDrive = vbNullString
End If
Call GetVolumeInformation(sDrive, vbNullString, 0, GetSerialNumber, ByVal 0&, _
ByVal 0&, vbNullString, 0)
End Function
Private Sub Command1_Click()
Dim sDrive As String
sDrive = InputBox("Enter drive for checking SN")
MsgBox Hex$(GetSerialNumber(sDrive))
End Sub