Hi,
i´ve a problem with usb devices and WMI. I´m writing a program (c#) to identify usb devices. Now i´ve to know the drive letter, the usb interal serial number (not the one, which Windows creates) and the VID/PID of the device. With WMI i´m able to read the drive letter and the internal serial number of all connected devices. But i can´t read the drive letter and the serial number only of the device i´ve connected at this moment.
Does anybody know, how to read out the three properties of a just connected usb device?
P.S.: I hope, this is the right forum to ask...
Loading

Roei BarRank #1,271 · 1.4K reputationPosted Aug 29, 2009, 12:41 PM EDT
/ browse all USB WMI physical disks foreach(ManagementObject drive in new ManagementObjectSearcher( "select * from Win32_DiskDrive where InterfaceType='USB'").Get()) { // associate physical disks with partitions foreach(ManagementObject partition in new ManagementObjectSearcher( "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" + drive["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get()) { Console.WriteLine("Partition=" + partition["Name"]); // associate partitions with logical disks (drive letter volumes) foreach(ManagementObject disk in new ManagementObjectSearcher( "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass = Win32_LogicalDiskToPartition").Get()) { Console.WriteLine("Disk=" + disk["Name"]); } } // this may display nothing if the physical disk // does not have a hardware serial number Console.WriteLine("Serial=" + new ManagementObject("Win32_PhysicalMedia.Tag='" + drive["DeviceID"] + "'")["SerialNumber"]); }dont forget to mark this as "Accepted Answer"
L Tiger6 reputationPosted Aug 30, 2009, 7:19 AM EDT
i´ve tested the code with ten usb devices. But no SerialNumber was displayed at every device and the PID/VID isn´t there, too :(
EDIT:
Ok, i found out, that the SerialNumber is not available in Windows XP and earlier.
Instead of the SerialNumber the Signature will be a better option for XP and later. I´ll post the code, when i´ve tested it...
L Tiger6 reputationPosted Sep 2, 2009, 11:05 AM EDT
now i´ve the code to determine the Signature, the VolumeSerialNumber and the drive letter of a connected usb device (WMI classes UsbControllerDevice, DiskDrive and LogicalDisk). But now i´ve to know the VID/PID or the usb classes (HID, Biometrics,...) of the device. Does anybody know how to figure out the VID/PID or the usb classes out of the known properties (signature, volumeserialnumber, drive letter)?