Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-27-2012, 07:49 AM   PM User | #1
jnvu_16
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
jnvu_16 is an unknown quantity at this point
Is it possible to detect a USB flash drive being inserted by a client using javascrip

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.^_^
jnvu_16 is offline   Reply With Quote
Old 06-27-2012, 07:56 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by jnvu_16 View Post
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 06-27-2012, 08:31 AM   PM User | #3
jnvu_16
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
jnvu_16 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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.
jnvu_16 is offline   Reply With Quote
Old 06-27-2012, 08:26 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-27-2012, 08:38 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by felgall View Post
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?"
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 06-27-2012, 09:46 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-27-2012, 10:20 PM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Philip M View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-27-2012, 11:15 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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??
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-28-2012, 08:13 AM   PM User | #9
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Old Pedant View Post
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/1...al-file-system

and an answer to this question in other forums:-

http://forums.devshed.com/javascript...ng-916270.html
http://www.webdeveloper.com/forum/sh....php?p=1212828
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 06-28-2012 at 08:26 AM..
Philip M is offline   Reply With Quote
Old 06-28-2012, 09:22 PM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-29-2012, 08:09 AM   PM User | #11
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Old Pedant View Post
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 ) 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).
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 06-29-2012 at 08:54 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.