By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

Device Manager listing in VB.Net

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.