views:

234

answers:

7

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.

+5  A: 

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

Henk Holterman
The devil's in the details, and this answer's quite the saint. 'd be nice, though, to spice it up a little with specifics regarding, say, plug-in type > language version > language module/library > sample code.
luvieere
@luvieere: My answer is limited to the information that querying USB (or any other) hardware is (far) outside of what client side web software is allowed to do. You will need platform-specific plugins that the user will have to allow specifically. Some users will not be able to do this.
Henk Holterman
@luvieere: This is the best answer, unfortunately for you. You're gonna have to deploy some kind of 3rd party code (outside of your web app and the client's browser) on the client machine. Taking that into account, it might be easier to write a cross-platform app than to write plug-ins for each type of browser on each type of OS. I'd go for a very simple and minimalistic .NET or Java app if I was you.
Allon Guralnek
This is the best answer and question op should tick it as "the answer". I use linux and windows. Used to use Solaris. What platform would you like to have USB prober ... please specify? For obvious security reasons, your web browser would not let you access local resources like the file and dev systems beyond the restricted resource-envelope of the browser.
Blessed Geek
@Blessed Geek Chrome OS is a browser by itself; and an operating system. So I'd see the security argument go dull right there - it's a specific case of a browser that NEEDS to access system resources. I'm expecting browser software to "grow up" already from the sandbox. There are attempts: full-trust XBAP, Out-of-Browser Silverlight, all of which are, however, limited in some other way and do not fit my purpose.
luvieere
@luviere, XBAP and OOB SL are desktop apps built with web trchnology. They require quite a bit of install on the user end. Browsers are _not_ growing up in that (unsafe) direction.
Henk Holterman
@Henk Holterman The operating system's safety should not be the left to the browser. Parts of the OS core that need to be restricted should be, by the OS itself. I want to be able to interact online not only with my mouse and keyboard, but also with my webcam, joystick and other USB devices. From the user's perspective, it shouldn't matter if it's a web app: he sees it on the screen, it should be able to access his data, just like a desktop app.
luvieere
@luviere, how would you protect the user from malicious sites reading your USB sticks, GPS location and taking (secret) pictures with your WebCam?
Henk Holterman
+1  A: 

You will need to write yourself a plugin for this.

Brad
Make this helpful, add some detail. What specific technology, what module, what kind of access?
luvieere
A: 

Impossible to do it with standard javascript.

Might work with ActiveX(Only IE and Windows) or Flash or a browser extension(per OS).

letronje
Flash sounds promising. Expand, please.
luvieere
I don't think that Flash can do this. But maybe someone knows different?
Henk Holterman
+2  A: 

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

mhambra
I'm trying to avoid additional software that is for this use only. I'd go for Flash or Silverlight, in light of their coverage of browsers and OSes.
luvieere
@luvieere: Flash and Silverlight are 'safe' technologies that __won't__ work for you. By definition you will need something ugly like ActiveX.
Henk Holterman
A: 

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.

Gleno
+1  A: 

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 !!!

jknair
+1  A: 

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

luvieere