473,382 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Retrieving USB pendrive Vendor id, Product id and Serial Number

I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) Has anybody done it before?
Sep 15 '12 #1
2 12410
zmbd
5,501 Expert Mod 4TB
Alanckar

Please post the code you've been using as someone here might catch where to add the parsing.
When posting the code, select the code block and then click on the <CODE/> button in the formatting bar.
Sep 15 '12 #2
This is the code which gives details of all devices connceted via USB. Not able it modify the query for only externally connected PenDrive.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.Management;
  6. using System.IO;
  7.  
  8. namespace MyWMITry
  9. {
  10.     static class Program
  11.     {
  12.        static void Main()
  13.       {
  14.         //writing to text file d:\\wordpressmod1.txt
  15.         TextWriter tw = new StreamWriter("d:\\MyWMITry.txt");
  16.  
  17.         ManagementScope scope = new ManagementScope("root\\CIMV2");
  18.         scope.Options.EnablePrivileges = true;
  19.         string Win32_USBControlerDevice = "Select * From Win32_USBControllerDevice";
  20.         ObjectQuery query = new ObjectQuery(Win32_USBControlerDevice);
  21.         ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  22.         foreach (ManagementObject mgmtObj in searcher.Get())
  23.         {
  24.            string strDeviceName = mgmtObj["Dependent"].ToString();
  25.            string strQuotes = "'";
  26.            strDeviceName = strDeviceName.Replace("\"", strQuotes);
  27.            string[] arrDeviceName = strDeviceName.Split('=');
  28.            strDeviceName = arrDeviceName[1];
  29.            string Win32_PnPEntity = "Select * From Win32_PnPEntity "
  30.                + "Where DeviceID =" + strDeviceName;
  31.            ManagementObjectSearcher mySearcher = 
  32.                new ManagementObjectSearcher(Win32_PnPEntity);
  33.            foreach (ManagementObject mobj in mySearcher.Get())
  34.            {
  35.                string strDeviceID = mobj["DeviceID"].ToString();
  36.                string[] arrDeviceID = strDeviceID.Split('\\');
  37.                tw.WriteLine("Device Description : " 
  38.                        + mobj["Description"].ToString());
  39.                if (mobj["Manufacturer"] != null)
  40.                {
  41.                    tw.WriteLine("Device Manufacturer : " 
  42.                        + mobj["Manufacturer"].ToString());
  43.                }
  44.                 tw.WriteLine("Device Version ID & Vendor ID : " + arrDeviceID[1]);
  45.                 tw.WriteLine("Device ID : " + arrDeviceID[2].Trim('{', '}'));
  46.                 tw.WriteLine();   
  47.            }           
  48.        }
  49.         // close the stream
  50.         tw.Close();
  51.             }
  52.         }
  53.     }
Sep 15 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
15
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
79
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
1
by: Paul | last post by:
Hi Guys, I have written an application in Visual C#, I wish to add serial number validation dll to the installer, how do I go about doing this. Thanks in advance. Paul Mathebula
10
by: Terry Olsen | last post by:
Does anyone know how to retrieve the system serial number? I'm writing an auditing program and need to grab that little bit of info. Thanks!
14
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
6
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk...
1
by: Uriah Piddle | last post by:
Hi Gang, I'm looking for some best practices advice on using a product serial number. After validating the serial number in InstallShield I can save it to the registry. I have it in mind to...
0
Airslash
by: Airslash | last post by:
Hello, I've written a class that resembles a hard drive. I'm already able using the Windows API to get information such as the remaining free bytes, the sectors and clusters,a nd it all works...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.