5

I am developing C# application which needs to find any USB port is free for use or not.

Is there any C# class or WMI query to determine USB Port is free for use or not?

Suppose, If a machine has 5 USB ports and out of which 2 are already occupied by mouse ,keyboard and remaining 3 are free. So I need to identify these ports which are not in use.

Is there any win32 class for this so I can use P/Invoke

Regards,

Amol.

cyberj0g
  • 3,707
  • 1
  • 19
  • 34
  • Have a look at http://stackoverflow.com/questions/27965098/c-sharp-how-do-i-check-usb-ports-with-usb-hub-and-used-controller – DerApe Jul 23 '15 at 06:11

1 Answers1

2

Take a look at that answer. I think you need to inspect Availability property of each Win32_USBHub to determine if device is connected to that port. However, there may be difficulties with USB hubs.

if ((int)device.GetPropertyValue("Availability")>3)
    //port is free
Community
  • 1
  • 1
cyberj0g
  • 3,707
  • 1
  • 19
  • 34