如何从浏览器获取 USB 设备列表 [英] How to get USB devices List from Browser

查看:101
本文介绍了如何从浏览器获取 USB 设备列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种基于浏览器的技术可以让我查询客户端当前连接的 USB 设备 - 特别是这些设备的名称和设备 ID.当然,我同意客户必须允许并确认此类活动.

What browser-based technology would allow me to query the client's currently connected USB devices - specifically name and device id of these. Of course, I'm ok with the client having to allow and confirm such an activity.

我不在乎它是否在低级别使用 WMI、直接访问或某种其他类型的访问层,我想要的只是能够从浏览器中使用它.我很欣赏代码示例,而且我对独立于浏览器的解决方案感到非常满意.

I don't care if at low-level, it uses WMI, direct access or some other sort of access layer, all I want is to be able to use it from within a browser. I'd appreciate code samples and I'd be extra happy with a browser-independent solution.

推荐答案

我有点失望,因为我没有尝试至少给我一个部分的解决方案.虽然我找不到独立于浏览器的解决方案,但我想出了一个用于 Windows 上的 IE 的解决方案,使用 WMI,更准确地说是 WbemScripting.SWbemLocator ActiveX 对象.总比没有好,比你不能那样做"要好.

I'm a bit disappointed by the lack of trying to at least give me a partial solution. Although I wasn't able to find a browser-independent solution, I came up with one for IE on Windows, using WMI, more precisely the WbemScripting.SWbemLocator ActiveX Object. It's better than nothing, better than "you can't do that".

所以,对于其他感兴趣的人,这里是:

So, for anyone else interested, here it is:

    function pollConnectedDevices()
    {
     var locator = new ActiveXObject("WbemScripting.SWbemLocator");
     var conn = locator.ConnectServer(".", "root\\cimv2");
     var result = conn.ExecQuery("Select * From Win32_USBHub");
     var enumer = new Enumerator(result);

     for (;!enumer.atEnd();enumer.moveNext ())
     {
       var hub = enumer.item ();

       alert(hub.Name + " " + hub.DeviceId);
     }

     setTimeout("pollConnectedDevices()",1000);
   }
   setTimeout("pollConnectedDevices()",1000);

是的,它仅适用于 Windows 上的 IE.是的,它确实需要用户的许可才能做它的事情.但是,是的,这是有可能的,它可以完成我需要它做的事情.

Yes, it is only on IE on Windows. Yes, it does need the user's permission to do its thing. But, YES, it is something, it is possible, it does what I need it to do.

如果其他人知道另一种方式 - 我在这里谈论的是代码,而不是意见,我仍在寻找其他浏览器和操作系统的部分解决方案.USB 设备查询是一件有趣的事情,尽管存在各种争论,我还是说它是软件,它应该做某事,而不是阻止您做某事".

If anyone else knows another way - and I'm talking here about code, not opinions, I'm still looking for partial solutions for other browsers and OSes. USB device querying is an interesting thing to have and in spite of all the arguments, I say that "it's software, it's supposed to do something, not prevent you from doing something".

这篇关于如何从浏览器获取 USB 设备列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆