Solved

Retrieve Unique ID Number of Thumb Drive

Posted on 2007-03-29
6
7,708 Views
Last Modified: 2013-11-14
Using a .bat file and the command line, (Windows XP) I have been asked to try to get the ID# off of a USB thumb drive.  I know how to do this for the hard drive, but now my client wants the unique identifier off of a thumb drive.
0
Comment
Question by:fmwebschool
6 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18818410
I guess if you attach something to the USB port, you can talk to it using Java Comm API and that will give you a port identifier for the same. Or see

http://today.java.net/pub/a/today/2006/07/06/java-and-usb.html
0
 
LVL 26

Expert Comment

by:lnkevin
ID: 18845429
Plug your USB in any PC, then download and save SIW program in your C:
Double click on the program, locate storage devices. Under interface tab, you will see USB and its ID

http://www.shareup.com/SIW-download-23742.html

K
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 18859000
You can get the volume serial number (Ok, not exacly the same as the device ID) with a simple shell script using WMI

Here is an exmple to demonstrate the concepts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_LogicalDisk",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_LogicalDisk instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "DriveType: " & objItem.DriveType
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
    Wscript.Echo "VolumeName: " & objItem.VolumeName
    Wscript.Echo "VolumeSerialNumber: " & objItem.VolumeSerialNumber
Next
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:fmwebschool
ID: 18931954
Thank you so much for the code!
0
 

Author Comment

by:fmwebschool
ID: 18932936
Hi Graye,

Recently you posted on Experts exchange code to retrieve the volume serial number of a thumbdrive - your code:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_LogicalDisk",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_LogicalDisk instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "DriveType: " & objItem.DriveType
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
    Wscript.Echo "VolumeName: " & objItem.VolumeName
    Wscript.Echo "VolumeSerialNumber: " & objItem.VolumeSerialNumber


Is it posible to retrieve the actual hardware serial number of the parent device for that volume?  That would be amazingly helpful!

Thank you so much for your time, and any guidance you can give.

In Kindness
Stephen K Knight
0
 
LVL 41

Expert Comment

by:graye
ID: 18936058
That's bit more complicated to do...  it takes a lot of low-level programming to get the "String Descriptor" from the USB Device Driver.  Also not all usb devices support serial numbers.    

About the best you can do is to use the identifier that Microsoft generates during it's Plug and Play negotiation.  It is generally understood (but not documented) that the PnPDeviceID is generated the same way on all PCs and all versions of Windows.

Take a look at the PnPDeviceIDs of two "identical" USB devices, notice where the values differ:

PNPDeviceID: USBSTOR\DISK&VEN_&PROD_USB_FLASH_MEMORY&REV_6.50\03716B60A130B8F8&0
PNPDeviceID: USBSTOR\DISK&VEN_&PROD_USB_FLASH_MEMORY&REV_6.50\0B317B6080E24882&0
                                                                                                                         ^^^^^^^^^^^^^
Although technically, the "03716B60A130B8F8" and "0B317B6080E24882" values are not the device serial number, they will probably do in your case.

You'd get the PnPDeviceID from the "raw" disk drive using the Win32_DiskDrive class

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_DiskDrive",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_DiskDrive instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "InterfaceType: " & objItem.InterfaceType
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Model: " & objItem.Model
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Next
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Choosing CentOS 16 79
backup strategy concern 5 77
Which NAS is best for small businesses 5 41
Help Required 2 29
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now