[python-win32] Read USB memory stick serial number
Tim Golden
mail at timgolden.me.uk
Tue Dec 29 22:01:27 CET 2009
python at bdurham.com wrote:
> 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?
> 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.
Try using Win32_DiskDrive instead. I'm not 100% sure (read: I'm
about 1% sure) what constitutes the USB serial number. The only
thing I'm fairly sure about is that it's *not* the volume label.
The PNPDeviceID looks good, even if it might need a bit of parsing:
<code>
import wmi
c = wmi.WMI ()
for usb in c.Win32_DiskDrive (InterfaceType="USB"):
print usb.PNPDeviceID
</code>
TJG
More information about the python-win32
mailing list