[英]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. 我正在开发C#应用程序,需要找到任何USB端口是否可以免费使用。
Is there any C# class or WMI query to determine USB Port is free for use or not? 是否有任何C#类或WMI查询来确定USB端口是否可以免费使用?
Suppose, If a machine has 5 USB ports and out of which 2 are already occupied by mouse ,keyboard and remaining 3 are free. 假设,如果一台机器有5个USB端口,其中2个已被鼠标占用,键盘和其余3个是免费的。 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 有没有任何win32类,所以我可以使用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. 我认为您需要检查每个Win32_USBHub的
Availability
属性以确定设备是否连接到该端口。 However, there may be difficulties with USB hubs. 但是,USB集线器可能存在问题。
if ((int)device.GetPropertyValue("Availability")>3)
//port is free
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.