[python-win32] Read USB memory stick serial number

python at bdurham.com python at bdurham.com
Tue Dec 29 21:42:45 CET 2009


Apparently retrieving the serial number of a USB memory stick is
much more complicated than one would think.

Is there a published Python recipe for determining a USB memory
stick's device level serial number under Windows and/or
Linux/Mac?

My Windows research follows my signature. Any feedback
appreciated.

Regards,
Malcolm

1. Here's a VBS script that attempts to use WMI to retrieve a USB
serial number. This script reports my USB drive as PHYSICALDRIVE4
with an empty serial number. Based on this experiment, it looks
like WMI does not have access to the information we're looking
for.

set svc = getobject ( "winmgmts:root\cimv2" )
set objEnum = svc.execQuery ( "select SerialNumber from
win32_physicalMedia ")
s1 = ""
for each obj in objEnum
    s1 = s1 + obj.GetObjectText_ + VBCR
next
wscript.echo s1

2. Here's what I found on my 64-bit Windows 7 Professional
registry using the following registry key I discovered during my
research on this topic[1]:
- Key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR\Enum
- Value: 0 = USB\VID_13FE&PID_1D00\5B7A11000302
Here's how the above value breaks out (text in parentheses are my
own notes):
- VID: 13FE (vendor id; Kingston Technology Company Inc.)
- PID: 1D00 (product id; DataTraveler 2.0 1GB/4GB Flash Drive)
- S/N: 5B7A11000302

Unfortunately, I don't know how one would identify a specific
device if multiple devices were present (I don't have multiple
memory sticks to test against yet). I assume that one technique
would be to enumerate against similar keys and/or values (0...N)?
I also don't know how portable this technique (key/value) is
across various flavors of Windows.
3. Here's what VOL returns from CMD shell via VOL D:
Volume serial number: 7644-2554

This serial number can be changed by a user via the LABEL
command. This serial number does not appear to be mathematically
related to the USB serial number.

References:

[1] USBDeview is a small utility that lists all USB devices that
are currently connected to your computer, as well as all USB
devices that you previously used. For each USB device, extended
information is displayed: Device name/description, device type,
serial number (for mass storage devices), the date/time that
device was added, VendorID, ProductID, and more.
http://www.nirsoft.net/utils/usb_devices_view.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20091229/283a1a6a/attachment.htm>


More information about the python-win32 mailing list