Click here to Skip to main content
Sign Up to vote bad
good
See more: C++MFC
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 29 Oct '10 - 1:27

Comments
deepratna - 20 Apr '13 - 7:42
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.

3 solutions

  Permalink  
Comments
Archit9373284448 - 30 Oct '10 - 1:31
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
  Permalink  
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 GetUSBDevices()
{
List devices = new List();
 
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; }
}
}
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 178
1 Tadit Dash 144
2 Santhosh G_ 140
3 Sergey Alexandrovich Kryukov 134
4 Espen Harlinn 120
0 Sergey Alexandrovich Kryukov 10,348
1 OriginalGriff 7,965
2 CPallini 4,241
3 Rohan Leuva 3,522
4 Maciej Los 3,184


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 14 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid