...

View Full Version : Is it possible to detect a USB flash drive being inserted by a client using javascrip



jnvu_16
06-27-2012, 07:49 AM
I'm working on a project at the moment that would somehow detect a USB Flash drive being inserted. It was easy at first when I used ASP.NET. However, that is for server-side programming, and now I need to somehow find a way to enable USB detection from the client-side, thus, I should be using javascript on this one. I just need to know;

is this possible?

If yes, could you show me how to do it?

Thanks! I would really appreciate it if you could reply as soon as possible.^_^

Philip M
06-27-2012, 07:56 AM
I'm working on a project at the moment that would somehow detect a USB Flash drive being inserted. It was easy at first when I used ASP.NET. However, that is for server-side programming, and now I need to somehow find a way to enable USB detection from the client-side, thus, I should be using javascript on this one. I just need to know;

is this possible?

If yes, could you show me how to do it?

Thanks! I would really appreciate it if you could reply as soon as possible.^_^

Simple answer - no, not possible.

JavaScript has no capability to access the client's operating system or the Windows registry, or alter the default behaviour of the browser.

jnvu_16
06-27-2012, 08:31 AM
Simple answer - no, not possible.

JavaScript has no capability to access the client's operating system or the Windows registry, or alter the default behaviour of the browser.

Thanks for the quick reply. That was kinda disappointing since I was asked to deliver this project as soon as possible. And I really need to find a way to somehow determine the drives in the client's side. Thanks anyway.:(

felgall
06-27-2012, 08:26 PM
JavaScript can access files but only if you run the script outside the browsers - for example in a desktop JavaScript application written to run using Adobe Air. The security issues are completely different where the person running the code has specifically chosen to download and install on their local computer to what applies in the browser.

JavaScript running on the server (eg. node.js) also has file access but only to files on the server.

Philip M
06-27-2012, 08:38 PM
JavaScript can access files but only if you run the script outside the browsers - for example in a desktop JavaScript application written to run using Adobe Air. The security issues are completely different where the person running the code has specifically chosen to download and install on their local computer to what applies in the browser.

JavaScript running on the server (eg. node.js) also has file access but only to files on the server.

All very true, but for the life of me I do not see how the information is in any way relevant to the question "Is it possible to detect a USB flash drive being inserted by a client using Javascript?"

Old Pedant
06-27-2012, 09:46 PM
I would like to point out that this *CAN* be done *IF*:
(a) the browser in use is MSIE
(b) the user has marked the site in question as a "Trusted Site"
(c) the user allows the web page to use a ActiveX controls.

In fact, it's not even hard under those circumstances. Though, to be fair, there's no way to get a message about the flash drive being inserted. You'd just have to poll all the drives when the page first loads, to find out which ones exist, and then periodically (e.g., using setInterval) check to see if a new drive has been detected.

felgall
06-27-2012, 10:20 PM
All very true, but for the life of me I do not see how the information is in any way relevant to the question "Is it possible to detect a USB flash drive being inserted by a client using Javascript?"

You assumed that the JavaScript in question is running in a web browser. The Op did not specify that the script was necessarily running in a browser and so I simply pointed out that the restriction only applies where it is running in a browser. Something that needs to know if a usb drive has been inserted is more likely to be a desktop application than a web page even if it is written in JavaScript.


Old Pedant has pointed out that calling activeX would also provide a way to do it from within Internet Explorer - to that could be added calling either Java or Flash from JavaScript and having that other language pass the information back to JavaScript just as activeX would - the difference being that the Java or Flash could be installed in any browser.

Old Pedant
06-27-2012, 11:15 PM
I'm suprised that Flash would have direct access to the file system. Does this mean we should stop trusting Flash in web pages? Or does Flash that gets access need to have the same user-permission checks as (for example) ActiveX in MSIE does?

For Java, don't you need a SIGNED applet to do this? Is there an equivalent to SIGNED for Flash??

Philip M
06-28-2012, 08:13 AM
I'm suprised that Flash would have direct access to the file system. Does this mean we should stop trusting Flash in web pages? Or does Flash that gets access need to have the same user-permission checks as (for example) ActiveX in MSIE does?

For Java, don't you need a SIGNED applet to do this? Is there an equivalent to SIGNED for Flash??

More info at
http://stackoverflow.com/questions/1811736/can-flash-action-script-read-and-write-local-file-system

and an answer to this question in other forums:-

http://forums.devshed.com/javascript-development-115/is-it-possible-to-detect-a-usb-flash-drive-being-916270.html
http://www.webdeveloper.com/forum/showthread.php?p=1212828

Old Pedant
06-28-2012, 09:22 PM
Aha! So Felgall was wrong about Flash! It can't do it any more than JavaScript can, and for the same reasons.

I know that Java can, but again only through the use of SIGNED applets. Which costs money to get the needed certification.

But it's annoying that this was cross-posted. He won't get more answers from me.

Philip M
06-29-2012, 08:09 AM
But it's annoying that this was cross-posted. He won't get more answers from me.

iBall/bullant etc. (who seems to have been banned yet again :thumbsup::thumbsup:) says there is no rule against cross-posting in different forums, and he himself does it. :(

Like you I think posting the same questiion in multiple forums is thoughtless and bad manners. People do not want to waste time answering a question when it has perhaps already been answered elsewhere.There are few things in forums more irritating than taking the time to unsnarl someone's markup, javascript and css, figure out the fix, and post it only to find you've wasted your time because a duplicate post in another forum has already been answered.

If you post in multiple forums you will find that you may not get an answer in any of them. If after a decent period of time you have had no response in one forum, then by all means post the same question in another.

I still do not see how an application running under Adobe Air could detect that a pen drive had been inserted. I think the answer is the one I gave first - not possible (in non-IE browsers).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum