Discussion:
How to uniquely identify a USB-HID device ?
(too old to reply)
MAV
2010-01-14 15:55:01 UTC
Permalink
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]
2010-01-14 22:42:34 UTC
Permalink
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.
Post by MAV
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!
MAV
2010-01-16 01:23:01 UTC
Permalink
Вес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.
Post by Doron Holan [MSFT]
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.
Post by MAV
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!
.
Leo Havmøller
2010-01-15 06:42:44 UTC
Permalink
Post by MAV
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.
MAV
2010-01-16 01:24:17 UTC
Permalink
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.
Post by Leo Havmøller
Post by MAV
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.
Pavel A.
2010-01-16 03:14:26 UTC
Permalink
Post by MAV
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
Post by MAV
Post by Leo Havmøller
Post by MAV
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
2010-01-15 09:02:49 UTC
Permalink
Post by MAV
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
***@storagecraft.com
http://www.storagecraft.com
MAV
2010-01-16 01:28:26 UTC
Permalink
Post by Maxim S. Shatskih
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 ?
Maxim S. Shatskih
2010-01-17 18:45:03 UTC
Permalink
Post by MAV
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.
Post by MAV
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.
--
Maxim S. Shatskih
Windows DDK MVP
***@storagecraft.com
http://www.storagecraft.com
Philip Ries [MSFT]
2010-01-18 21:15:57 UTC
Permalink
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
Post by MAV
Post by Maxim S. Shatskih
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 ?
unknown
2010-03-22 18:56:28 UTC
Permalink
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. ***@versalent.biz



MAV wrote:

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

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 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!

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 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
Maxim S. Shatskih
Windows DDK MVP
***@storagecraft.com
http://www.storagecraft.com

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
Maxim S. Shatskih
Windows DDK MVP
***@storagecraft.com
http://www.storagecraft.com

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)

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

MAV wrote:

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

I think this is exactly what you need: http://msdn.microsoft.
I think this is exactly what you need: http://msdn.microsoft.com/en-us/library/ms790939.aspx


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
h***@gmail.com
2020-05-05 18:28:45 UTC
Permalink
Post by unknown
I think this is exactly what you need: http://msdn.microsoft.com/en-us/library/ms790939.aspx
HidD_GetSerialNumberString
---
frmsrcurl: http://msgroups.net/microsoft.public.development.device.drivers/How-to-uniquely-identify-a-USB-HID-device
Thanks man. MSDN has gone to chit.

Loading...