Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Detect removable media

Posted on 2004-09-14
25
Medium Priority
?
862 Views
Last Modified: 2008-01-09
Hi all.

I am making some software that syncronizes files on a local hard drive with the files on an USB 2.0 flash drive. The drive is totally plug and play, so after I plug the drive into my USB port, it shows up in my computer as "Removable Disk (G:)"

My question is this: What can I do to
1) Detect when the drive is plugged in
2) Detect what drive letter it is

Thanks for any help, I will up the points if this is very complicated.
0
Comment
Question by:srcalc
  • 14
  • 6
  • 5
25 Comments
 
LVL 4

Author Comment

by:srcalc
ID: 12060432
Perhaps I can use some sort of code with the FileSystemWatcher?
0
 
LVL 4

Author Comment

by:srcalc
ID: 12061166
I know I'm being impatient, but I'm raising the points for an answer.
0
 
LVL 18

Assisted Solution

by:armoghan
armoghan earned 800 total points
ID: 12061444
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:armoghan
ID: 12061448
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12061458
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12061469
Try the last link
0
 
LVL 4

Author Comment

by:srcalc
ID: 12063036
OK I will see what I can do with those and get back to you
0
 
LVL 4

Author Comment

by:srcalc
ID: 12070463
I am having trouble trying to figure out what the code in that last link is doing. Can you identify the important parts?
0
 
LVL 4

Author Comment

by:srcalc
ID: 12070552
The 'DeviceArrival' event from sysinfo.ocx that the author talks about in http://www.experts-exchange.com/Storage/Q_20833060.html seems to work, but only for VB 6.0. Any ideas?
0
 
LVL 4

Author Comment

by:srcalc
ID: 12070611
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12071612
have you tried the first link on your Removable Disks?. This seems simple
http://www.codeproject.com/dotnet/devicevolumemonitor.asp


>>Perhaps a VB .NET implimentation of this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/removable_storage_manager_functions.asp

I could not find an implemnation for this :(
0
 
LVL 4

Author Comment

by:srcalc
ID: 12071826
I downloaded the file from codeproject.com
The program can detect when i put a CD in, but not when i put in a USB drive...
0
 
LVL 10

Accepted Solution

by:
Clif earned 1200 total points
ID: 12076679
I just tested my USB flash drive with the sysinfo.ocx on VB.NET.  The 'DeviceArrival' event works for me.

    Private Sub AxSysInfo1_DeviceArrival(ByVal sender As Object, ByVal e As AxSysInfoLib.DSysInfoEvents_DeviceArrivalEvent) Handles AxSysInfo1.DeviceArrival
        Debug.WriteLine("DeviceArrival ")
        Debug.WriteLine(e.deviceData)
        Debug.WriteLine(e.deviceID)
        Debug.WriteLine(e.deviceName)
        Debug.WriteLine(e.deviceType)
    End Sub

Produces the following output:
DeviceArrival
0
64

2
0
 
LVL 4

Author Comment

by:srcalc
ID: 12076793
Clif,
Where are you getting AxSysInfo?
0
 
LVL 10

Expert Comment

by:Clif
ID: 12076832
I added the VB6 sysinfo ocx to the project, then dropped it on the form.  I double clicked it to get event code, then selected DeviceArrival from the event dropdown list.

What I posted is what VB.NET inserted.
0
 
LVL 4

Author Comment

by:srcalc
ID: 12076858
when i drop the sysinfo.ocx into my form, it says that i need a license
0
 
LVL 10

Expert Comment

by:Clif
ID: 12076891
You will need to install VB6 on your development machine.
0
 
LVL 4

Author Comment

by:srcalc
ID: 12076932
Thanks for the fast feedback. Actually I just found a link that show me how to do it with my VS .NET CD:
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q318/5/97.asp&NoWebContent=1

Let me work with the control and make sure I have no other questions about it, then I will award points.
0
 
LVL 10

Expert Comment

by:Clif
ID: 12076958
I did not know this.  Perhaps I should award you points?  :)
0
 
LVL 4

Author Comment

by:srcalc
ID: 12077116
Why does the DeviceArrival event not tell me the device name?

DeviceArrival      ===The event
0                       ===DeviceType - OEM-defined device type.
64                     ===DeviceID - G:\
                         ===Where is the name??
2                       ===DeviceData - OEM-specific function value. Possible values depend on the device.
0
 
LVL 10

Expert Comment

by:Clif
ID: 12077211
Don't know.

Perhaps it's something internal to the USB flash drive.  It just doesn't contain a name.

Did you get yours to work?  

Do you have a USB mouse?  Try unplugging and replugging it in.  Does it display a name?
0
 
LVL 4

Author Comment

by:srcalc
ID: 12077462
The event only seems to trigger for devices that show up as a drive. EX:

My USB mouse didn't trigger it; niether did my old TI-83 graphlink
My USB drive did trigger it; my digital camera also did (It shows up as a drive letter)

I didn't get a name for my camera either
0
 
LVL 10

Expert Comment

by:Clif
ID: 12078013
Oh well, I suppose you don't really need a name.  "64" should be the device ID to be on the look out for.  No, "64" doesn't mean "Drive G:", it should just mean "Flash Drive".  You might want to check it for other flash drives (including various manufacturers) just to be sure.

As far as telling which drive it's in, that's going to be a bit trickier.  "Removable Disk" could be a flash drive, or it could be a zip drive or ???.  It should take the first available letter after "C", but you'd have to know that the flash drive wasn't plugged in before your application started.

In any event, it's a little beyond my ability at this point.
0
 
LVL 4

Author Comment

by:srcalc
ID: 12078667
OK, thanks for you help. Actually, I think that 64 is the drive letter. 2^(5+1) = 64 and G is the 5th letter of the alphabet. A would be 1, B 2, C 4, D 8, E 16, F 32, G 64. At any rate, thanks for the code you pasted, it helped. Give me a little more time to experiment and I will award points.
0
 
LVL 4

Author Comment

by:srcalc
ID: 12080723
Clif,
If you post on my pointer link http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21133767.html within a day i will award you points. Thanks!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question