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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get a CD or diskette serial number at runtime?

Status
Not open for further replies.

Sometimes76

Programmer
May 29, 2001
15
PT
...any ideas??

Thanks in advance!
Luís
 
Give this a try

'Declare the following in the declarations section of your code
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

'GetSerialNumber Procedure - Put this in the module or form where it is called.
Function GetSerialNumber(sDrive As String) As Long
Dim SerialNum As Long
Dim Res As Long
Dim tmp1 As String
Dim tmp2 As String
tmp1 = String$(255, Chr$(0))
tmp2 = String$(255, Chr$(0))
'call the API function
Res = GetVolumeInformation(sDrive, tmp1, Len(tmp1), SerialNum, 0, 0, tmp2, Len(tmp2))
'return the serial number of the drive
GetSerialNumber = SerialNum
End Function


Hope this works for you. Anything is possible, the problem is I only have one lifetime.[thumbsup2]
 
Or add a reference to the Microsoft Scripting Runtime, and then:
[tt]
Option Explicit

Private Sub Command1_Click()
MsgBox GetSerialNumber("c") 'FSO is smart, so "c", "c:", "c:\" are all valid inputs here
End Sub

Public Function GetSerialNumber(sDrive As String) As Long
Dim fso As FileSystemObject
Set fso = New FileSystemObject
GetSerialNumber = fso.GetDrive(sDrive).SerialNumber
Set fso = Nothing
End Function
[/tt]
Ignore luddites who advise against using the FileSystemObject.
 
Thanks a lot, guys! :) Both solutions worked, I really apreciate your help!

Thanks once again!
Luís
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top