Solved

Detect removable media

Posted on 2004-09-14
25
810 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 200 total points
ID: 12061444
0
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Accepted Solution

by:
Clif earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now