473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Checking if USB device is plugged in


Hi,

I'm looking for a way of checking whether a specific USB device (a
webcam) is plugged in. I have the Vendor and Product ID numbers for the
device.

I found an article (http://www.vsj.co.uk/articles/display.asp?id=600)
with code sample that does the trick for human input devices (mouse,
keyboard, ...) but am struggling for my webcam.

Any help appreciated, thanks.

Gary
Nov 10 '06 #1
2 4514
"beaker" <ra*********@notrealcompanyIhope.comwrote in message
news:Ox****************@TK2MSFTNGP04.phx.gbl...
>
Hi,

I'm looking for a way of checking whether a specific USB device (a webcam)
is plugged in. I have the Vendor and Product ID numbers for the device.

I found an article (http://www.vsj.co.uk/articles/display.asp?id=600) with
code sample that does the trick for human input devices (mouse, keyboard,
...) but am struggling for my webcam.

Any help appreciated, thanks.

Gary
Gary,

It's easy outside of .NET if you handle the WM_DEVICECHANGE message. Below
is a snippet of a MFC program that does that. It shouldn't be hard to map
this to .NET, here's a discussion of just that, I haven't tried it myself:

http://www.codecomments.com/archive2...-4-185490.html

My MFC (edited) code snippet:

BOOL CConfigWinDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
{
DEV_BROADCAST_DEVICEINTERFACE *devInterface;
DEV_BROADCAST_HDR *brHeader = (DEV_BROADCAST_HDR *)dwData;

switch (nEventType)
{
case (DBT_DEVICEARRIVAL):
if (brHeader && brHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
devInterface = (DEV_BROADCAST_DEVICEINTERFACE *)brHeader;
if (strstr(strupr(devInterface->dbcc_name), "VID_0403&PID_6006"))
{
// my device plugged in
// do something cool
}
else
{
// some other device plugged in
}
}
else
{
// unknown device plugged in
}
}
break;

// other cases
}
[snip]
Nov 10 '06 #2
andrew queisser wrote:
"beaker" <ra*********@notrealcompanyIhope.comwrote in message
news:Ox****************@TK2MSFTNGP04.phx.gbl...
>>Hi,

I'm looking for a way of checking whether a specific USB device (a webcam)
is plugged in. I have the Vendor and Product ID numbers for the device.

I found an article (http://www.vsj.co.uk/articles/display.asp?id=600) with
code sample that does the trick for human input devices (mouse, keyboard,
...) but am struggling for my webcam.

Any help appreciated, thanks.

Gary


Gary,

It's easy outside of .NET if you handle the WM_DEVICECHANGE message. Below
is a snippet of a MFC program that does that. It shouldn't be hard to map
this to .NET, here's a discussion of just that, I haven't tried it myself:

http://www.codecomments.com/archive2...-4-185490.html

My MFC (edited) code snippet:

BOOL CConfigWinDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
{
DEV_BROADCAST_DEVICEINTERFACE *devInterface;
DEV_BROADCAST_HDR *brHeader = (DEV_BROADCAST_HDR *)dwData;

switch (nEventType)
{
case (DBT_DEVICEARRIVAL):
if (brHeader && brHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
devInterface = (DEV_BROADCAST_DEVICEINTERFACE *)brHeader;
if (strstr(strupr(devInterface->dbcc_name), "VID_0403&PID_6006"))
{
// my device plugged in
// do something cool
}
else
{
// some other device plugged in
}
}
else
{
// unknown device plugged in
}
}
break;

// other cases
}
[snip]


Thanks, the article you gave the link to does half of what I need, and I
can now detect when the device is plugged in - but I still need to know
if the device is present when my app starts (and so misses the
appropriate event for that method.)

Any ideas?

Thanks again.
Nov 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mccormick.Johnw | last post by:
Hello, ... I am John McCormick (Systems Programmer ) and I am currently working on a python program which will connect (user) specified inputs and connect them to (user) selected outputs (like...
0
by: Hank | last post by:
Hi, I am writing a windows service application which manage image capturing device in C#.NET. When the service is running, how it automatically detect when there is a new device plugged in (say...
4
by: Charles Law | last post by:
Is there an event or notification that my application can receive when a USB device (or other) is plugged in? I have looked at WMI as this appears to be the right area but cannot see how to get...
3
by: Steve | last post by:
I want to check if a USB device is availble on a system. Is this possible? I see it in the Device Manager, so I think it must be possible "somehow" :)
0
by: tuism | last post by:
Hi all, I hava java application that wants to receive windows events when a device like an USB or Firewire is plugged in. I know how to do this natively in C++ where I can register a window to...
0
by: zhensoftware | last post by:
USB storage devices have gained popularity. It can be host to viruses, Trojans, hacker toolkits, worms or other forms of malicious programs. For example, when you plug your USB disk into a computer...
1
by: rajeshrocks2006 | last post by:
Hi, Can anybody help me, how can i detect when any unauthorized device is plugged into the USB port? In my case an unauthorized USB device pen drive. I need to be able to detect if any pen...
0
by: queries365 | last post by:
Hey, I have a device for which I have to install the drivers. For this, I have the required .sys files as also the .inf file. I wish to have the drivers installed before I plug in my device so...
4
by: saintme | last post by:
Hello all, I have a USB modem stick and a PoE network device. I want to connect the device to the Internet using the USB stick. The device has no other interfaces, so I must use its RJ-45 port. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.