Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,
i am developing a program in C++/MFC (not in C#) and i want to know is there any method by which i can get device id / hardware id of USB drives.

thanks i advance.
Posted
Comments
deepratna 20-Apr-13 7:42am    
Hi to all,
i am developing a program in C# and i want to know is there any method by which i can get HID Complaint Device Unique ID .

which is used as License . Application is used when we connected HID Device.

thanks i advance.

 
Share this answer
 
Comments
Archit9373284448 30-Oct-10 1:31am    
Thanks man... :) +5 rep
what I suggest is to use query WMI through winapi to get vid and pid
I don't familiar with MFC but winapi
 
Share this answer
 
namespace ConsoleApplication1
{

using System.Text;
using System.Data.Odbc;
using System.Data;
using System.Web;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Data.OleDb;
using System.Text.RegularExpressions;
using System.Linq;



using System;
using System.Collections.Generic;
using System.Management; // need to add System.Management to your project references.

class Program
{

static void Main(string[] args)
{
var usbDevices = GetUSBDevices();

foreach (var usbDevice in usbDevices)
{
string m_pendid;

Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}, USBVersion: {3}, SystemName: {4}",
usbDevice.DeviceID, usbDevice.PnpDeviceID, usbDevice.Description, usbDevice.usbversion, usbDevice.SystemName);

// m_pendid=catch["usbDevice.DeviceID"];
m_pendid = usbDevice.DeviceID;



Console.WriteLine("Test" + m_pendid);



}

// Console.Write("DeviceID :DeviceID");
Console.Read();




}

static List<usbdeviceinfo> GetUSBDevices()
{
List<usbdeviceinfo> devices = new List<usbdeviceinfo>();

ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
collection = searcher.Get();

foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description"),
(string)device.GetPropertyValue("USBVersion"),
(string)device.GetPropertyValue("SystemName")

));

}

collection.Dispose();
return devices;
}
}

class USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string pnpDeviceID, string description, string usbversion1, string SystemName2)
{
this.DeviceID = deviceID;
this.PnpDeviceID = pnpDeviceID;
this.Description = description;
this.usbversion = usbversion1;
this.SystemName = SystemName2;
}
public string DeviceID { get; private set; }
public string PnpDeviceID { get; private set; }
public string Description { get; private set; }
public string usbversion { get; private set; }
public string SystemName { get; private set; }
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900