Reputation: 5212
The closest that I can find is:
ManagementObjectSearcher("SELECT * FROM win32_PnPSignedDriver");
But it returns far too many info and I am not sure if the returned values have the same format between different drives
Info returns by:
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
Doesn't have the Drive letter, and the Serial Number is in-correct for some drives.
Upvotes: 2
Views: 656
Reputation: 29919
So the actual question being asked here is "why does WMI (Windows' implementation of CIM)) return different values to Nirsoft's USBDeview", and the answer is that USBDeview is simply using part of the PNPDeviceId as the serial number for removable devices.
For example, I have a USB flash drive attached which has the serial number E0D55E6CBD13F3A1284600B0
according to USBDeview. If I run wmic diskdrive get serialnumber
the result is a literal 0
.
But, if I run wmic diskdrive get pnpdeviceid
:
USBSTOR\DISK&VEN_<omitted>&REV_\E0D55E6CBD13F3A1284600B0&0
which is identical to the "serial number" reported by USBDeview if you strip off everything up to and including the last slash, and from and including the last ampersand.
The reason seems to either be that there is no specification for encoding serial numbers, so various manufacturers do it differently and thus Windows can't interpret it uniformly; or that Windows (WMI) is interpreting this data incorrectly. There's a very old and very long thread discussing this on Microsoft's own forums, if you want some more background.
As USBDeview merely uses what Windows provides it (it does not install its own driver to inspect hardware), presumably the author decided the easiest way to "get" serial number data was to instead use something reliable, i.e. PNPDeviceId.
Upvotes: 5