473,493 Members | 4,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Device Manager listing in VB.Net

Does anyone have any VB.Net code to get the devices listed / enumerated
in the Device Manager listing.
I'm trying to figure out if a device (it's actually a digital camera)
is connected to the computer. When it's plugged in (Firewire), it
shows up in Device Manager under the "Imaging Devices" catagory. When
it's not plugged in, it doesn't show up. When it's plugged in, there
is a registry key that says ReferenceCount = 1, and when it's not
plugged in, it says it = 0. The problem with checking that registry
entry is that it doesn't depend on the camera model -- it depends on
the specific camera. If I plug in a different Fuji camera of the very
same model, it will add a new registry entry with a different big long
number. So I got that working on my first camera, but when I plugged
in the second camera it no longer worked. Apparently it leaves
registry litter around for every camera you've ever plugged in even if
you've since unplugged it.
Is there someway to do it with the WMI? Or is there a simpler way?
Thanks,
Mark H.

Nov 21 '05 #1
1 19301
OK, I finally found an answer to my own question. Here is the code. I
hope someone else will find it useful, be able to adapt it, and save
the hours of time it took me to figure it out.
Mark H.
' Checks the Device Manager entry for the Fujifilm camera.
' If a Fuji S20 camera is detected, the function will return True.
' If it's not there, the function will return False.
' Requires a reference to "System.Management" to be added to your
project's references.
Public Function FujiCameraDetected() As Boolean
Try

' See if the Fujifilm camera shows up in the device manager.
Dim info As System.Management.ManagementObject
Dim search As System.Management.ManagementObjectSearcher
Dim deviceName As String
Dim result As DialogResult
Dim cameraIsSeenByWindows As Boolean = False
Dim showDebugPrompts As Boolean = False

search = New System.Management.ManagementObjectSearcher("SELECT *
From Win32_PnPEntity")

For Each info In search.Get()
' Go through each device detected.
deviceName = CType(info("Caption"), String) ' Get the name of
this particular device.
If showDebugPrompts Then
result = MessageBox.Show(deviceName, "Device Listing",
MessageBoxButtons.OKCancel)
If result = DialogResult.Cancel Then Exit For
End If
If InStr(deviceName, "Fujifilm", CompareMethod.Text) > 0 Then
' The device is the Fujifilm camera we're looking for.
cameraIsSeenByWindows = True
If showDebugPrompts Then
result = MessageBox.Show("The Fuji camera is seen by windows.",
"Camera Recognized", MessageBoxButtons.OKCancel)
If result = DialogResult.Cancel Then Exit For
End If
Exit For ' Bail out - no need to check the rest of the
devices.
End If
Next
If cameraIsSeenByWindows Then
If showDebugPrompts Then MsgBox("Windows does not see the Fuji
Camera.", MsgBoxStyle.Information)
Return True
Else
If showDebugPrompts Then MsgBox("Windows sees the Fuji Camera.",
MsgBoxStyle.Information)
Return False
End If

Catch ex As Exception
Call ShowErrorWithoutLog(ex.Message, ex.StackTrace)
End Try

End Function

Nov 21 '05 #2

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

Similar topics

5
34301
by: Logan McKinley | last post by:
I was wondering if there is any way for me to read the device manager in my C# program? I have a program that crashes when some third party hardware is not installed or is set to the wrong port...
1
14101
by: jayderk | last post by:
I was wondering if anyone knows of a way to open the device manager, OR system properties? thanks in advanced, Jay
1
3553
by: donler | last post by:
Does anyone know how to read from the Device Manager. I would like to get a list of all devices and if possible, get some information about each device. thx much
1
1525
by: Cameron K | last post by:
ok i haven't had internet in about 3 months but i just got dial up at home and my modem wasn't responding so what do i find in the device manager...NOTHING!!!! i have already tried turning plug and...
2
8853
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: -----------------------------...
1
7282
by: karan.shashi | last post by:
Hello to all the C# gurus :), I'm interested in whether it's possible to enable and/or disable devices in the device manager programmatically using C#. Anybody with some insight on this? I'm...
0
2042
by: vivelafaq | last post by:
Hi everyone, I want to find a way to get the label of a com port like displayed in the device manager in ports : e.g : PC | _Ports (COM & LPT) | _CP210x USB to UART Bridge Controller (COM3).
3
2852
by: rosath | last post by:
I want to select a device in device manager based on the name of the device. How can I achieve this using perl? Any help is truely appreciated.
0
1494
by: =?Utf-8?B?QmV2eV9KZXRlcg==?= | last post by:
Using XP Pro as an administrator. Experiencing 3 problems: 1) Device Manager is empty in both normal & safe modes, 2) F8 will not take me into Safe Mode but MSConfig will, & 3) Computer folder...
0
7118
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
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.