How to get USB devices List from Browser
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.
I don't care if at low-level, it uses WMI, direct access or some other sort of access layer, 开发者_StackOverflow中文版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.
You can't do that from a Browser (with reasons). You'll need some plug-in that the user has to install.
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);
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.
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".
IE ActiveX, IE toolbar, Netscape plugin wrapper (for Opera/Windows, Firefox/Windows, probably Chrome/Windows) => WMI. Presumably any such stuff would be banned by any scrapyard-grade antivirus software.
You can: a> go that way, b> go with smart cards native support instead of making usb security dongles c> write your own software, that will start a webserver at 127.0.0.1 and access it from javascript on your page (where the installation download is offered).
You will need to write yourself a plugin for this.
A java applet . You can use http://javax-usb.org/ .
And well it has been done using java applets http://forums.sun.com/thread.jspa?threadID=5371360
So a solution surely exists !!!
Impossible to do it with standard javascript.
Might work with ActiveX(Only IE and Windows) or Flash or a browser extension(per OS).
Hm, from the top of my head, I think XBAP might help you out. http://www.xbap.org/. From then on it's just c# with some #usblib.
Edit Hm, it says that it runs executes in sandbox mode. And it seems to be IE-only pluggin. I guess XBAP is a miss.
精彩评论