CodeItBetter Programming Another VB Programming Blog

How to Get Floppy/CD/Hard Drive Serial Number

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'File/Folder Handling - How to Get Floppy/CD/Hard Drive Serial Number

Option Explicit
 
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
 
Function GetSerialNumber(strDrive As String) As Long
    Dim SerialNum As Long, res As Long
    Dim Temp1 As String, Temp2 As String
    Temp1 = String$(255, Chr$(0))
    Temp2 = String$(255, Chr$(0))
    res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
    GetSerialNumber = SerialNum
End Function
 
'How can I call this function:
Private Sub Command1_Click()
    Call MsgBox(GetSerialNumber("C:\"))
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.