Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > Detect a USB Device

Reply
Thread Tools Display Modes

Detect a USB Device

 
 
USB Device User
Guest
Posts: n/a

 
      05-25-2010
I have a USB printer and I know its vendor ID and product ID. How can I know
it is connected from my C# application?
 
Reply With Quote
 
 
 
 
USB Device User
Guest
Posts: n/a

 
      05-25-2010
BTW, I am trying to use winapi calls not wmi.

"USB Device User" wrote:

> I have a USB printer and I know its vendor ID and product ID. How can I know
> it is connected from my C# application?

 
Reply With Quote
 
Philip Ries [MSFT]
Guest
Posts: n/a

 
      05-25-2010
One way is via Setup API (it's a managed API so you will have to PInvoke
it). Start with function SetupDiGetClassDevs.

USB Device User wrote:
> BTW, I am trying to use winapi calls not wmi.
>
> "USB Device User" wrote:
>
>> I have a USB printer and I know its vendor ID and product ID. How can I know
>> it is connected from my C# application?

 
Reply With Quote
 
USB Device User
Guest
Posts: n/a

 
      05-25-2010
I tried SetupDi functions. It is easy for HID to get GUID and VID/PID. But
for general USB device, how can I get GUID and VID/PID from the api calls?

"Philip Ries [MSFT]" wrote:

> One way is via Setup API (it's a managed API so you will have to PInvoke
> it). Start with function SetupDiGetClassDevs.
>
> USB Device User wrote:
> > BTW, I am trying to use winapi calls not wmi.
> >
> > "USB Device User" wrote:
> >
> >> I have a USB printer and I know its vendor ID and product ID. How can I know
> >> it is connected from my C# application?

> .
>

 
Reply With Quote
 
Pavel A.
Guest
Posts: n/a

 
      05-25-2010
"USB Device User" <> wrote in message
news:60FB1C84-C1E3-42EA-9848-...
> I tried SetupDi functions. It is easy for HID to get GUID and VID/PID. But
> for general USB device, how can I get GUID and VID/PID from the api calls?


Have you tried SetupDiGetClassDevs ?
-- pa

> "Philip Ries [MSFT]" wrote:
>
>> One way is via Setup API (it's a managed API so you will have to PInvoke
>> it). Start with function SetupDiGetClassDevs.
>>
>> USB Device User wrote:
>> > BTW, I am trying to use winapi calls not wmi.
>> >
>> > "USB Device User" wrote:
>> >
>> >> I have a USB printer and I know its vendor ID and product ID. How can
>> >> I know
>> >> it is connected from my C# application?

>> .
>>

 
Reply With Quote
 
USB Device User
Guest
Posts: n/a

 
      05-25-2010
Yes, I did. I can pass Null to enumerate all devices. But which api call
should I use to get VID/PID?

"Pavel A." wrote:

> "USB Device User" <> wrote in message
> news:60FB1C84-C1E3-42EA-9848-...
> > I tried SetupDi functions. It is easy for HID to get GUID and VID/PID. But
> > for general USB device, how can I get GUID and VID/PID from the api calls?

>
> Have you tried SetupDiGetClassDevs ?
> -- pa
>
> > "Philip Ries [MSFT]" wrote:
> >
> >> One way is via Setup API (it's a managed API so you will have to PInvoke
> >> it). Start with function SetupDiGetClassDevs.
> >>
> >> USB Device User wrote:
> >> > BTW, I am trying to use winapi calls not wmi.
> >> >
> >> > "USB Device User" wrote:
> >> >
> >> >> I have a USB printer and I know its vendor ID and product ID. How can
> >> >> I know
> >> >> it is connected from my C# application?
> >> .
> >>

 
Reply With Quote
 
Maxim S. Shatskih
Guest
Posts: n/a

 
      05-26-2010
> Yes, I did. I can pass Null to enumerate all devices. But which api call
> should I use to get VID/PID?


SetupDiGetDeviceRegistryProperty returns a hardware ID.

And there is a doc page about how the USB HW IDs are composed from VID/PID.

--
Maxim S. Shatskih
Windows DDK MVP

http://www.storagecraft.com

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a

 
      05-28-2010
"Maxim S. Shatskih" <> wrote:
>
>> Yes, I did. I can pass Null to enumerate all devices. But which api call
>> should I use to get VID/PID?

>
>SetupDiGetDeviceRegistryProperty returns a hardware ID.
>
>And there is a doc page about how the USB HW IDs are composed from VID/PID.


Is there? The format has not changed since Windows 95 OSR2, but I thought
it was officially undocumented. Do you remember which page this is on?
--
Tim Roberts,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
Wilhelm Noeker
Guest
Posts: n/a

 
      05-28-2010
Tim Roberts wrote:
> "Maxim S. Shatskih" <> wrote:
>>> Yes, I did. I can pass Null to enumerate all devices. But which api call
>>> should I use to get VID/PID?

>> SetupDiGetDeviceRegistryProperty returns a hardware ID.
>>
>> And there is a doc page about how the USB HW IDs are composed from VID/PID.

>
> Is there? The format has not changed since Windows 95 OSR2, but I thought
> it was officially undocumented. Do you remember which page this is on?


I recently stumbled into it in a section titled "Enumeration of USB
Composite Devices":

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
 
Reply With Quote
 
Maxim S. Shatskih
Guest
Posts: n/a

 
      05-28-2010
> Is there? The format has not changed since Windows 95 OSR2

There was an MSDN page somewhere which documents the PnP IDs layout for all common buses.

--
Maxim S. Shatskih
Windows DDK MVP

http://www.storagecraft.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Unable to unload driver in Win 7 Tim Roberts Windows Vista Drivers 2 12-08-2009 12:24 PM
My PnP Monitor is seen as Non PnP??? Colin Windows Vista Hardware 1 11-29-2007 05:01 PM
Re: Vista and IMate Jamin WMDC 6 RTM Problem Gary Waliczek [MSFT] ActiveSync 4 02-23-2007 06:20 PM
Trouble with driver on Windows Vista Beta 2 sujatha Windows Vista Installation 0 06-08-2006 06:44 PM
ActiveSync 4.1 Still does not work... ckelsoe ActiveSync 9 01-06-2006 03:15 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59