Link to home
Start Free TrialLog in
Avatar of Dan Violet Sagmiller (He/Him)
Dan Violet Sagmiller (He/Him)Flag for United States of America

asked on

Hardware Serial Numbers.

My Needs:  
   I am trying to write a piece of software that will utilize USB Keys, to distinguish between users.

My Question:
    I presume that each piece of hardware hols a serial identification, along with model or vendor info.  (based on the fact that hard drives carry this)  
    I want to know how to access the Serial Number, and if possible, Model and vendor info for a USB key (Flash disk)
Avatar of jake072
jake072
Flag of Canada image

Hardware vendor should provide you with that information...

Unless you mean just a datastick...

Jake
Avatar of Dan Violet Sagmiller (He/Him)

ASKER

I will be programming in VB.Net.  I need the application to be able to determine the Serial number of any given Drive.  Specifcally, USB Flash disks.
ASKER CERTIFIED SOLUTION
Avatar of jake072
jake072
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just to rewrite the function exactly as in VB6:

    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 = New String(Chr(0), 255)
        Dim sDriveType As String = New String(Chr(0), 255)
        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 sDrive.Substring(1) = ":" Then
            sDrive = sDrive & "\"
        End If

        Return GetVolumeInformation(sDrive, sVolumeName, 255, lAns, 0, 0, sDriveType, 255)
    End Function
    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 = New String(Chr(0), 255)
        Dim sDriveType As String = New String(Chr(0), 255)
        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 sDrive.Substring(1) = ":" Then
            sDrive = sDrive & "\"
        End If

        Return GetVolumeInformation(sDrive, sVolumeName, 255, lAns, 0, 0, sDriveType, 255)
    End Function

Sorry :) (Still works, either way :) )...

Jake
I was hoping .NET had a specific solution, and perhaps it does.  but for now it will have to wait another day.  

Thank you for the assistance, and I will use the API method.
hpdvs2,

I tried to find a .NET solution, however, I couldn't find one.  For now, that's what you have to use.  I believe that in the new 2.0 Framework there will be methods to access this directly (Not positive).

Jake