0

From what I have read and tried myself I am starting to think this is not possible; but if you don't don't ask you don't get...

I am making a tool that formats USB sticks for staff at work (it adds branding, instructions, handbooks etc). Whilst doing this I am attempting to store the "serial/Unique identifier" for the device in a database so that should I find a lost memory stick I can find out who the original owner was, even if it has been reformated!

I got this snippet from another answer on SO

        Dim driveNames As New List(Of String)
    For Each drive As DriveInfo In My.Computer.FileSystem.Drives
        Try
            Dim fso As Scripting.FileSystemObject
            Dim oDrive As Scripting.Drive

            fso = CreateObject("Scripting.FileSystemObject")

            oDrive = fso.GetDrive(drive.Name)

            ListBox1.Items.Add(drive.Name & "   " & oDrive.SerialNumber)
        Catch ex As Exception
        End Try

    Next
End Sub

This returns a number, but that changes when the drive is formatted.

I also tried modifying a snippet I got from online (CodeProject) I think.

        'Check for valid drive letter argument. 
    ToolStripStatusLabel1.Text = "Fetching Device Serial ('" & DriveLetter & "' Validating drive letters)"
    Dim ValidDriveLetters As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    If ValidDriveLetters.IndexOf(DriveLetter) <> -1 Then
        If DriveLetter.Length = 1 Then
            ToolStripStatusLabel1.Text = "Fetching Device Serial ('" & DriveLetter & "' Creating Disk Management Object)"
            Dim Disk As New System.Management.ManagementObject("Win32_LogicalDisk.DeviceID=""" & DriveLetter & ":""")
            ToolStripStatusLabel1.Text = "Fetching Device Serial ('" & DriveLetter & "' Creating Disk Property)"
            Dim DiskProperty As System.Management.PropertyData
            For Each DiskProperty In Disk.Properties
                ToolStripStatusLabel1.Text = "Fetching Device Serial ('" & DriveLetter & "' Reading " & DiskProperty.Name & ": " & DiskProperty.Value & ")"
                'Threading.Thread.Sleep(1000)
                If DiskProperty.Name = "VolumeSerialNumber" Then
                    Return DiskProperty.Value.ToString  '.ToString 'Return the volume serial number. 
                End If
            Next DiskProperty
        End If
    End If
    Return Nothing 'Invalid drive letter.

This currently returns the volume serial (best result I could get right now), that obviously changes when the drive is formatted.

I have looked through the property names but I am yet to find something to uniquely identify the drive itself rather than its volumes.

Is there a property that I can read that would be unique to each device? (even the same the manufacturer/model)

OR

Am I going about this the wrong way? I also considered partitioning the USBs with a hidden partition and then storing the volume serial of that. If an end user formats the drive via Explorer they are only going to wipe the visible partition rather than my secret hidden one...but this seems like a workaround rather than an actual solution?

Please note, I am not a VB.net wizard, web is more my thing (I may need some hand holding at times - but I try my best!)

Robin Wright
  • 303
  • 1
  • 12
  • Wrong WMI class. The serial number is provided by the [Win32_DiskDrive](https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-diskdrive) class – Jimi Nov 28 '18 at 16:46
  • Explored the option of creating a hidden partition. I would need to list the partitions but I don't seem to be able to find a common link between what the user sees and what DiskPart utilises. ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk") will show user understandable things like partition labels etc but that doesn't have disk/partition indexes to use in DiskPart. – Robin Wright Nov 28 '18 at 16:46
  • @Jimi I just saw your comment, I will check that out. – Robin Wright Nov 28 '18 at 16:48
  • 1
    [Get serial number of usb storage device](https://stackoverflow.com/questions/49118708/get-serial-number-of-usb-storage-device-in-net-core-2-1?answertab=active#tab-top) – Jimi Nov 28 '18 at 16:48

0 Answers0