-
Jan 18th, 2016, 02:50 PM
#1
Thread Starter
Member
Find Specific Attached Device by VID and Disable It
I've got an app I wrote that needs to detect if a USB device w/ a particular VID is attached, and then disable it. I've pieced together the bones of what I think should work to at least find the device by VID, though it's not working correctly, either.
Once I get this piece working and have the device, can I disable it using the System.Management class? Any tips on how to do this?
Code:
Public Sub DisableHIDDevice()
Dim USBClass As New System.Management.ManagementClass("Win32_USBControllerDevice")
Dim USBCollection As System.Management.ManagementObjectCollection = USBClass.GetInstances()
Dim USBDev As System.Management.ManagementObject
Dim DevVID As String
For Each USBDev In USBCollection
DevVID = USBCollection("deviceid").ToString()
If (DevVID =MYVID) Then
MsgBox(DevVID)
End If
Next USBDev
End Sub
I've downloaded and used the WMI Code Creator tool from Microsoft, but this doesn't seem to do what I'mn looking for either. It easily generated the code to FIND my device (root\cimv2\Win32_USBDevice), but the tool doesn't list an available method to set the Enable/disable.
Last edited by nobbyv; Jan 18th, 2016 at 03:24 PM.
-
Jan 19th, 2016, 03:07 AM
#2
Re: Find Specific Attached Device by VID and Disable It
Originally Posted by nobbyv
I've got an app I wrote that needs to detect if a USB device w/ a particular VID is attached, and then disable it. I've pieced together the bones of what I think should work to at least find the device by VID, though it's not working correctly, either.
Once I get this piece working and have the device, can I disable it using the System.Management class? Any tips on how to do this?
Code:
Public Sub DisableHIDDevice()
Dim USBClass As New System.Management.ManagementClass("Win32_USBControllerDevice")
Dim USBCollection As System.Management.ManagementObjectCollection = USBClass.GetInstances()
Dim USBDev As System.Management.ManagementObject
Dim DevVID As String
For Each USBDev In USBCollection
DevVID = USBCollection("deviceid").ToString()
If (DevVID =MYVID) Then
MsgBox(DevVID)
End If
Next USBDev
End Sub
I've downloaded and used the WMI Code Creator tool from Microsoft, but this doesn't seem to do what I'mn looking for either. It easily generated the code to FIND my device (root\cimv2\Win32_USBDevice), but the tool doesn't list an available method to set the Enable/disable.
Hi, I can't help you with your specific problem, but I've noticed a few things that I would change because they could be part of the problem:
1. The "MYVID" variable isn't declared anywhere, do you have "Option Explicit" turned on?
2. You shouldn't have "Option Strict" turned off: In the "DevVID = USBCollection("deviceid").ToString()" line you're specifying a string where an integer is expected and it can't even be converted to a valid number. To me this looks likely a likely suspect as to why your code isn't working.
3. You should consider using "Imports" statements at the top of your module.
4. Perhaps you should post all of your code instead of a fragment. It makes it easier for others to debug.
Last edited by Peter Swinkels; Jan 20th, 2016 at 03:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|