disk serial numbaer

Post Reply
sony
Posts: 18
Joined: Wednesday 14th June 2017 12:28am

disk serial numbaer

Post by sony » Thursday 05th October 2017 12:12am

Hello,
How to read the usb stick volume serial number?
Thank

Sony

stevedee
Posts: 42
Joined: Monday 20th March 2017 6:06pm

Re: disk serial numbaer

Post by stevedee » Thursday 05th October 2017 10:28am

This is one way of doing it:-

Code: Select all

Public Sub Main()
'this sub uses the list of links in: /dev/disk/by-id/
'...which includes the device identity and serial number

Dim strDisk As String
Dim strLink As String
Dim strName As String
Dim strSerial As String

  For Each strDisk In Dir("/dev/disk/by-id", "usb-*", gb.Link)
    strLink = Stat("/dev/disk/by-id/" & strDisk).Link
    strLink = "/dev/" & Right(strLink, - RInStr(strLink, "/"))
    If Len(strLink) = 8
      strDisk = Mid(strDisk, InStr(strDisk, "_") + 1)
      strDisk = Mid(strDisk, 1, InStr(strDisk, "-") - 1)
      strName = Replace(Left(strDisk, RInStr(strDisk, "_")), "_", " ")    
      strSerial = Mid(strDisk, RInStr(strDisk, "_") + 1, InStr(strDisk, "-") - 1)
      Print strName & " serNo: " & strSerial
    Endif
  Next  

End
Or you could use the Linux command: lsusb -v ...which must be run as root.
This will give you access to more device information (e.g. idProduct, idVendor, iProduct, iSerial, USB class)

User avatar
cogier
Site Admin
Posts: 115
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: USB disk serial number

Post by cogier » Thursday 05th October 2017 1:49pm

Here is another way of doing it. This works in Linux Mint but whether it will work in other distros is another matter.
USB Serial Number.jpg
USB Serial Number.jpg (29.69 KiB) Viewed 149 times
USB_Serial_Number.tar
(26.5 KiB) Downloaded 10 times
EDIT: - It does not work on the Raspberry Pi

sony
Posts: 18
Joined: Wednesday 14th June 2017 12:28am

Re: disk serial numbaer

Post by sony » Friday 06th October 2017 4:30am

Thank you very much

Sony

User avatar
jornmo
Site Admin
Posts: 127
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: disk serial numbaer

Post by jornmo » Saturday 07th October 2017 8:02pm

Hey Sony!

I like your TVs and loudspeakers :lol:

Sorry, I just could not help myself ;) I have a very dry sense of humour... Welcome (back) to the forums! :ugeek:

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest