简体   繁体   中英

How can I get the free USB ports in c#?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM