Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.^_^

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,625
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,625
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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
    Last edited by Philip M; 06-28-2012 at 08:26 AM.

    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.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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).
    Last edited by Philip M; 06-29-2012 at 08:54 AM.

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •