How to uniquely identify a USB-HID device ?

1130 views
Skip to first unread message

MAV

unread,
Jan 14, 2010, 10:55:01 AM1/14/10
to
Hello All!

I need to identify the USB port number to which the USB-HID device is
connected given a USB device name. I have a USB keyboard or mouse device
name like \.\Device\000000XXX - where XXX - is a number that changes each
time the system starts up, so I cannot rely on it. I need a number that
uniquely identifies USB port to which the device is connected, or maybe a hub
number and a port number on that hub. I cannot use VID and PID numbers since
there may be several similar devices connected to the system. Maybe there are
some IOCTL codes that I need to send to the device? I'm working from kernel
mode in Windows XP SP3. Please help!

Doron Holan [MSFT]

unread,
Jan 14, 2010, 5:42:34 PM1/14/10
to
no such information exists. why do you think you need to identify the port
it is attached to?

--

This posting is provided "AS IS" with no warranties, and confers no rights.


"MAV" <M...@discussions.microsoft.com> wrote in message
news:00A486FD-0BCD-434C...@microsoft.com...

Leo Havmøller

unread,
Jan 15, 2010, 1:42:44 AM1/15/10
to
> I cannot use VID and PID numbers since
> there may be several similar devices connected to the system.

Use the device serial number - thats what it's for.

Leo Havmøller.

Maxim S. Shatskih

unread,
Jan 15, 2010, 4:02:49 AM1/15/10
to
> I need to identify the USB port number to which the USB-HID device is

USB is just conceptually not designed to use numbered ports.

If, for instance, the laptop has several USB ports, then _the idea is that the same device will work the same way_ regardless of the port it is connected too. Several USB ports provide a nearly complete illusion of electric parallelism.

So, it is not a good idea to use USB port numbers anywhere. Use device instances instead, strongly tied to the device's embedded unique ID and not the port it is connected too. This is well-supported in Windows using PnP.

--
Maxim S. Shatskih
Windows DDK MVP
ma...@storagecraft.com
http://www.storagecraft.com

MAV

unread,
Jan 15, 2010, 8:23:01 PM1/15/10
to
Весause I have 8 identical USB keyboards and 8 identical USB mice connected
to the PC and I need a way to distinguish wheter this is keyboard #1, this is
keyboard #2, .... My driver receives the names of keyboards and mice in the
from of their device names, for example \.\Device\000000XXX and I need to
tell what is the number of this keyboard. I have a configure program where
user is asked to press buttons on keybords and mice and monitor the activity
of them. I already have the hook driver that does the monitoring job. I need
to somehow identify the keyboards and mice at every startup since
\.\Device\000000XXX is changing every time the system boots up. The port\hub
number would be great since nobody is going to recconect the keyboards and
mice.

"Doron Holan [MSFT]" wrote:

> .
>

MAV

unread,
Jan 15, 2010, 8:24:17 PM1/15/10
to
I have generic USB keyboards and mice and also PS\2 keyboards and mice
connected through USB<->PS\2 adapter. Neither of those have serial number.

MAV

unread,
Jan 15, 2010, 8:28:26 PM1/15/10
to
"Maxim S. Shatskih" wrote:

> So, it is not a good idea to use USB port numbers anywhere. Use device instances instead, strongly tied to the device's embedded unique ID and not the port it is connected too. This is well-supported in Windows using PnP.

I need a number or device ID that will not change every time the system
starts up. Could you please tell me how to retrieve such unique ID for
generic USB keyboard given a device name "\.\Device\000000XXX"? Maybe to send
some IOCTL's ?

Pavel A.

unread,
Jan 15, 2010, 10:14:26 PM1/15/10
to
"MAV" <M...@discussions.microsoft.com> wrote in message
news:EEA7C21F-BB9B-4BF9...@microsoft.com...

> I have generic USB keyboards and mice and also PS\2 keyboards and mice
> connected through USB<->PS\2 adapter. Neither of those have serial number.

Then maybe look at the USBview WDK sample program.
It collects the USB tree structure, and devices attached to each node.
--pa

Maxim S. Shatskih

unread,
Jan 17, 2010, 1:45:03 PM1/17/10
to
> I need a number or device ID that will not change every time the system
> starts up.

Port number will change on each re-plug.

> generic USB keyboard given a device name "\.\Device\000000XXX"?

If there is no unique ID in the USB config descriptor of the keyboard - then just plain impossible.

Philip Ries [MSFT]

unread,
Jan 18, 2010, 4:15:57 PM1/18/10
to
I don't know if you have the device instance path for each device. If
you do, or you can get it, you can make some SetupDi function calls to
get the port number. The sequence look something like:

SetupDiGetClassDevs
SetupDiEnumDeviceInfo
SetupDiGetDeviceProperty (DEVPKEY_Device_Address)

Reference: "Address" section at
http://msdn.microsoft.com/en-us/library/dd852021.aspx

guest

unread,
Feb 16, 2010, 5:28:04 AM2/16/10
to

johnursoleo

unread,
Mar 22, 2010, 2:56:28 PM3/22/10
to
I had exactly the same problem .. and wrote this C# DLL to provide the solution. From this package the DLL you want to ref in your dot NET code is HIDstring.dll . It allows you to get the serial number from any USB HID device for which you have a handle .. or any indexed string you defined.. again you need the handle.

http://www.versalent.biz/downloads/quad4dll.zip

HIDstring.dll is in this zip

Let me know how it works for you. jurs...@versalent.biz

MAV wrote:

How to uniquely identify a USB-HID device ?
14-Jan-10

Hello All!

some IOCTL codes that I need to send to the device? I am working from kernel


mode in Windows XP SP3. Please help!

Previous Posts In This Thread:

On Thursday, January 14, 2010 10:55 AM
MAV wrote:

How to uniquely identify a USB-HID device ?
Hello All!

some IOCTL codes that I need to send to the device? I am working from kernel


mode in Windows XP SP3. Please help!

On Thursday, January 14, 2010 5:42 PM
Doron Holan [MSFT] wrote:

no such information exists.
no such information exists. why do you think you need to identify the port
it is attached to?

--

This posting is provided "AS IS" with no warranties, and confers no rights.

On Friday, January 15, 2010 1:42 AM
Leo_Havm?ller wrote:

Use the device serial number - thats what it is for.Leo Havm??ller.
Use the device serial number - thats what it is for.

Leo Havm??ller.

On Friday, January 15, 2010 4:02 AM
Maxim S. Shatskih wrote:

USB is just conceptually not designed to use numbered ports.
USB is just conceptually not designed to use numbered ports.

If, for instance, the laptop has several USB ports, then _the idea is =
that the same device will work the same way_ regardless of the port it =
is connected too. Several USB ports provide a nearly complete illusion =
of electric parallelism.

So, it is not a good idea to use USB port numbers anywhere. Use device =
instances instead, strongly tied to the device's embedded unique ID and =
not the port it is connected too. This is well-supported in Windows =
using PnP.

--=20

On Friday, January 15, 2010 8:23 PM
MAV wrote:

??????
??????ause I have 8 identical USB keyboards and 8 identical USB mice connected


to the PC and I need a way to distinguish wheter this is keyboard #1, this is
keyboard #2, .... My driver receives the names of keyboards and mice in the
from of their device names, for example \.\Device\000000XXX and I need to
tell what is the number of this keyboard. I have a configure program where
user is asked to press buttons on keybords and mice and monitor the activity
of them. I already have the hook driver that does the monitoring job. I need
to somehow identify the keyboards and mice at every startup since
\.\Device\000000XXX is changing every time the system boots up. The port\hub
number would be great since nobody is going to recconect the keyboards and
mice.

"Doron Holan [MSFT]" wrote:

On Friday, January 15, 2010 8:24 PM
MAV wrote:

I have generic USB keyboards and mice and also PS\2 keyboards and
I have generic USB keyboards and mice and also PS\2 keyboards and mice
connected through USB<->PS\2 adapter. Neither of those have serial number.

"Leo Havm??ller" wrote:

On Friday, January 15, 2010 8:28 PM
MAV wrote:

"Maxim S.
"Maxim S. Shatskih" wrote:


I need a number or device ID that will not change every time the system
starts up. Could you please tell me how to retrieve such unique ID for
generic USB keyboard given a device name "\.\Device\000000XXX"? Maybe to send
some IOCTL's ?

On Friday, January 15, 2010 10:14 PM
Pavel A. wrote:

Then maybe look at the USBview WDK sample program.
Then maybe look at the USBview WDK sample program.
It collects the USB tree structure, and devices attached to each node.
--pa

On Sunday, January 17, 2010 1:45 PM
Maxim S. Shatskih wrote:

system=20Port number will change on each re-plug.
system=20

Port number will change on each re-plug.


If there is no unique ID in the USB config descriptor of the keyboard - =
then just plain impossible.

--=20

On Monday, January 18, 2010 4:15 PM
Philip Ries [MSFT] wrote:

I do not know if you have the device instance path for each device.
I do not know if you have the device instance path for each device. If


you do, or you can get it, you can make some SetupDi function calls to
get the port number. The sequence look something like:

SetupDiGetClassDevs
SetupDiEnumDeviceInfo
SetupDiGetDeviceProperty (DEVPKEY_Device_Address)

MAV wrote:

On Tuesday, February 16, 2010 5:28 AM
guest wrote:


HidD_GetSerialNumberString

---
frmsrcurl: http://msgroups.net/microsoft.public.development.device.drivers/How-to-uniquely-identify-a-USB-HID-device


Submitted via EggHeadCafe - Software Developer Portal of Choice
Join Lists with LINQ - SharePoint 2010
http://www.eggheadcafe.com/tutorials/aspnet/b0c1cd0d-fe82-444e-a16e-7d3fb7d38eca/join-lists-with-linq--sh.aspx

hollings...@gmail.com

unread,
May 5, 2020, 2:28:47 PM5/5/20
to
Thanks man. MSDN has gone to chit.
Reply all
Reply to author
Forward
0 new messages