/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@maurycyJun 27.2012 — It's not possible to do it in any web technology I know at this moment since it require access to user machine, although you can ask user if he inserted USB
Copy linkTweet thisAlerts:
@rnd_meJun 27.2012 — strictly speaking the answer is no.

you might be able to craft an autorun that pings your site, and then move the state from your site to the client app somehow, but it sounds like more trouble than it's worth.


what's the end goal?
Copy linkTweet thisAlerts:
@jnvu_16authorJun 28.2012 — Well, this was supposed to be for added user security. I'm planning to do something else now but it still involves the use of a USB flash drive. Tell me if this is possible though because it's still in theory as of now. It goes like this, I would enable the user to insert a flash drive and a textbox would be added just for that field. Once he inserts the USB flash drive, I would let my javascript read a txt file that I would somehow put in his flash drive and have it printed on that additional text box. Once again, is that possible though? And how do I do this?
Copy linkTweet thisAlerts:
@maurycyJun 28.2012 — Well there is a robust way to do it.

You could make interval that will attempt to access file:///[DriveLetter]:/yourFile.txt

But you can't tell what drive letter it will be on so you will have to test all drive letters A-Z every time. That's the only way I could think about "USB detect". If you go that way then you have to be sure to make an exception when user says it's plugged in but you can't find file but you will eventually figure it out.
Copy linkTweet thisAlerts:
@jnvu_16authorJun 29.2012 — how about the <input type = "file" />? It would enable me to ask permission to the user. However, I wouldn't want the user to find where I inserted the txt file, so is it possible for me to let the user select just the drive?
Copy linkTweet thisAlerts:
@Gray1989Jun 29.2012 — How about you get them to download a file with the correct privileges to do all of this? It shouldn't be much of a learning curve. Using HTML Applications (.hta instead of .html) you could get this job done (with JScript & WMI) and you won't have to worry about overcoming any security blockages. You would actually have full read/write access to the client machine AND be able to do all of the AJAX or whatever else you wanna use to communicate back with your server using HTML/JavaScript... Just a thought. You can also compile a .hta into a .exe file for better handling using a third-party tool.
Copy linkTweet thisAlerts:
@rnd_meJul 02.2012 — Once he inserts the USB flash drive, I would let my javascript read a txt file that I would somehow put in his flash drive and have it printed on that additional text box. Once again, is that possible though? And how do I do this?[/QUOTE]

yes, that is very possible.

here's a simple example of loading and somehow using a file from the local computer, thumbs drives included:

[CODE]
<!DOCTYPE html>
<html>
<head>
<title>reading file</title>
<script type="text/javascript">

var reader = new FileReader();

function readText(that){

if(that.files && that.files[0]){
var reader = new FileReader();
reader.onload = function (e) {
var output=e.target.result;
document.getElementById('main').innerHTML= output;
};//end onload()
reader.readAsText(that.files[0]);
}//end if html5 filelist support
}
</script>
</head>
<body>
<input type="file" onchange='readText(this)' />
<pre id="main"></pre>
</body>
</html>[/CODE]


while all this does is show the text, you can can do whatever you want with the [I]output [/I]variable.


you can use a large file as a key using an algorithm like this app uses to secure the contents of the data that you serve.

if everyone has the same large key and that key is not transmitted over the net, text ciphered with the key can be sent on the net without interception.
×

Success!

Help @jnvu_16 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...