Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:27am
Comments
deepratna at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Archit9373284448 at 30-Oct-10 1:31am
   
Thanks man... :) +5 rep
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

what I suggest is to use query WMI through winapi to get vid and pid
I don't familiar with MFC but winapi
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 14 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100