Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, 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.

like image 765
luvieere Avatar asked Sep 18 '10 19:09

luvieere


2 Answers

You can't do that from a Browser (with reasons). You'll need some plug-in that the user has to install.

like image 56
Henk Holterman Avatar answered Oct 15 '22 16:10

Henk Holterman


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".

like image 30
luvieere Avatar answered Oct 15 '22 16:10

luvieere