Drive Number

duvenhlc

Registered User.
Local time
Today, 19:00
Joined
Feb 4, 2008
Messages
54
Good day,

How can I read the serial number of a USB memory drive into a form?

Regards

Lance
 
DECS:
PHP:
Option Explicit

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
FUNCTION:
PHP:
Public Function DriveSerialNumber(ByVal Drive As String) As Long
    
    'usage: SN = DriveSerialNumber("C:\")
 
    Dim lAns As Long
    Dim lRet As Long
    Dim sVolumeName As String, sDriveType As String
    Dim sDrive As String

    'Deal with one and two character input values
    sDrive = Drive
    If Len(sDrive) = 1 Then
        sDrive = sDrive & ":\"
    ElseIf Len(sDrive) = 2 And Right(sDrive, 1) = ":" Then
        sDrive = sDrive & "\"
    End If
  
    sVolumeName = String$(255, Chr$(0))
    sDriveType = String$(255, Chr$(0))
    
    lRet = GetVolumeInformation(sDrive, sVolumeName, _
    255, lAns, 0, 0, sDriveType, 255)

DriveSerialNumber = MsgBox("The serial number " & _
                           "for drive " & _
                           sDrive & " is..." & lAns)

End Function
CALL:
PHP:
Function DisplayDriveSerial()

    Call DriveSerialNumber("DRIVE LETTER HERE")

End Function
 
Thanks it help me a lot. Is there a way to "outo detect" the usb drive's drive letter? My problem is that the drive letter may vary from PC to PC, this code will not be accesable for changes, or alternative is it possible to give the drive a name and then to search for that name.

Regards

Lance
 
nice david. i have no knowledge of this of this subject, as you probably know, but it sure looks like I do, doesn't it? :D

actually, one more obviously taken step by the OP and he would be just as smart as I am about this stuff.
 
Thanks Guys, I have used you inputs. Please see the attached result. This DB will detect the USB drive letter and then give the serial number.

Thanks.

Lance
 

Attachments

This is good stuff! :)

Is there also any way of getting the flash drive volume name
my drives called "robs drive" for example, and would like to be able to show this in a form

thanks guys

Rob :)
 
Hi Rob,

Here is something, I used it but please note it is not my stuff. I cant find the it on the forum again, wanted to add the link. Play with the code to suite you.

Lance
 

Attachments

Users who are viewing this thread

Back
Top Bottom