0

Good evening, I have a small challenge that I'm trying to get around. I have a user environment where all devices are 'built' using identical system images and identical hardware. It's a small point of sale environment. The software on the computers requires devices to be connected to particular USB other wise the devices will not work with the software. This presents a lot of issues as the cables aren't physically labelled.

I'm trying to create a small Visual Basic application which is able to check what device is connected to each USB port on the system. The program seems simple to me, but I've been having difficulty with the code for a few days. Is it possible to return the USB Port ID using the code below. I'm able to retrieve then DeviceID, but I now need to compare this with the USB ID to confirm it's in the correct port, how can I retrieve the USB Port ID/Name?

 Dim sc As New ManagementScope("\\DESKTOP-BA9EEM9\root\cimv2")

    Dim query As New ObjectQuery("Select * from Win32_USBHub")

    Dim searcher As New ManagementObjectSearcher(sc, query)
    Dim result As ManagementObjectCollection = searcher.Get()

    For Each obj As ManagementObject In result
        If obj("Description") IsNot Nothing Then
            ListBox1.Items.Add("Description:" & vbTab + obj("Description").ToString())
        End If
        If obj("DeviceID") IsNot Nothing Then
            ListBox1.Items.Add("DeviceID:" & vbTab + obj("DeviceID").ToString())
        End If
        If obj("PNPDeviceID") IsNot Nothing Then
            ListBox1.Items.Add("PNPDeviceID:" & vbTab + obj("PNPDeviceID").ToString())
        End If
        ListBox1.Items.Add("----------------------------------------")
user3516240
  • 365
  • 1
  • 6
  • 25
  • perhaps Devcon can help you? https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/devcon – user1234433222 Jul 03 '17 at 22:27
  • I'd need to install Devcon on all machines though. My plan to run the VB application was to copy the .exe over and execute remotely. So Devcon doesn't seem viable. Though it is Windows 8 Systems. – user3516240 Jul 03 '17 at 22:38
  • no you can just get the exe, its like 500kb, add it to your programs folder. https://superuser.com/questions/1002950/quick-method-to-install-devcon-exe – user1234433222 Jul 03 '17 at 22:42
  • I had a customer once when I was working at a computer shop, for some reason their wifi would drop out due to a driver crash, (they had the latest driver too) however if you were to uninstalled the driver from device manager, it would come back until the driver would crash again, anyways to cut a long story short they couldn't follow the instructions i gave them to remove the driver and reinstall it, so i made a c# console application that would use devcon to remove their wifi driver and to rescan for new hardware so it would reinstall with 1 click, this was with devcon in the programs folder. – user1234433222 Jul 03 '17 at 22:47
  • Thank you for your comments, How would I go about accessing devcon once it's in the programs folder though? Like how can I run it so my VB application can get the information? – user3516240 Jul 03 '17 at 22:54
  • I did it using cmd, I just made a process executed it within my programs folder and add the arguments that i wanted – user1234433222 Jul 03 '17 at 23:20
  • Can you use C#? If yes, then check https://stackoverflow.com/questions/27965098/c-sharp-how-do-i-check-usb-ports-with-usb-hub-and-used-controller. This might help you. – Shaibal Jul 04 '17 at 11:52

0 Answers0