Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 20th, 2006, 7:36 AM   #1
john Wesley
Hobbyist Programmer
 
john Wesley's Avatar
 
Join Date: May 2006
Location: United Kingdom
Posts: 119
Rep Power: 3 john Wesley is on a distinguished road
Send a message via MSN to john Wesley Send a message via Yahoo to john Wesley
Drive Insertion Detection

Hello everyone, It's been a couple of weeks I believe.

I have a question to ask about detecting when a disk is inserted.
a disk being either a floppy, CD, USB etc..

As you now windows automatically detects a Drive or Disk when inserted, and unless the option is disabled, it will prompt you with a dialog giving you options of what to do / how you want to open the data.

I am writing a program that needs the ability to know when a new drive letter is mounted. I have looked around the internet for a couple of days regarding this matter, and other than trying my damned hardest to re-write some C# code I have had no success. maybe somebody here has an idea?

Info : My program wants to be notified when there is a USB drive inserted and on the occasion of it being inserted the program will search the drive for a specific file, if the file exists it can carry out its duty, otherwise nothing is done.

I must thank anyone who even takes time to look at this thread.
__________________
Mona Lisa must of had the highway blues you can tell by the way she smiles..
john Wesley is offline   Reply With Quote
Old Jul 20th, 2006, 11:32 AM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Tricky. Depending on how you want to do it, there would be a few ways. Which is most effective, I don't know. In the old VB6, I would have used a timer probably, as I don't remember there being a control for it. But, with VB.NET, I figured there would be some control to help you with ths process. I've just been looking at the controls, and I can only see one that might help you. Check out the FileSystenWatcher (under components). I don't know how well it performs, but it seems to be the closeest thing to what you want, without actually coding a lot yourself. Hope it helps
Booooze is offline   Reply With Quote
Old Jul 21st, 2006, 8:47 AM   #3
john Wesley
Hobbyist Programmer
 
john Wesley's Avatar
 
Join Date: May 2006
Location: United Kingdom
Posts: 119
Rep Power: 3 john Wesley is on a distinguished road
Send a message via MSN to john Wesley Send a message via Yahoo to john Wesley
Well yes, as you mention there would be a few way's I would imagine. Thanks for bringing the FileSystemWatcher to my attention, as it happens I had started coding a routine to handle this but it is very 'Matchsticky' and 'Glued Together'.

Incase your curious Booooze I shall explain just a little.

I used a DriveListBox with a timer that refreshes every 2 seconds...

Then a ComboBox that grabs the number of drives in the DriveListBox also using a timer ticking slightly after the first...

The third item is a NumericUpDown that grabs the number contained in the ComboBox with a timer that ticks just under a second after timer number 2

If the NumericUpDown Value is ever smaller than the ComboBox Value then it searches the drives listed for the file I am looking for.

I know this is a real cowboy job but i was just playing around last night with a method of how to do this, I know there will be a lot of critisism for this but heyyy I can work with critisism.

Thanks for your info Booooze, I shall see how it pans out tonight with a FileSystemWatcher.
__________________
Mona Lisa must of had the highway blues you can tell by the way she smiles..
john Wesley is offline   Reply With Quote
Old Jul 21st, 2006, 10:59 AM   #4
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
yeah, I was going to say that you could just use timers and keep checking for the new drive, but as you said, it's liked glued together:p Although, If you would like to make your code that you are making a little more effiecient, I would suggest using the Directory class. e.g:

something = Directory.GetLogicalDrives

If you want more code, here is some code I developed in C# for a guy who needed it and he converted it VB.NET. Perhaps it might be of some use to you. It gets the Names and Volume labels of the drives.

        Dim drives As String() = Directory.GetLogicalDrives
        For Each drive As String In drives
            Dim di As DriveInfo = New DriveInfo(drive)
            Dim newlst1 As ListViewItem
            newlst1 = lstdrives.Items.Add(0)

            Try
                newlst1.Text = (drive + " (" + di.VolumeLabel + ")")

            Catch ex As Exception
                newlst1.Text = (drive & "")
            End Try

        Next

Anyways, good luck
Booooze is offline   Reply With Quote
Old Jul 21st, 2006, 11:41 AM   #5
john Wesley
Hobbyist Programmer
 
john Wesley's Avatar
 
Join Date: May 2006
Location: United Kingdom
Posts: 119
Rep Power: 3 john Wesley is on a distinguished road
Send a message via MSN to john Wesley Send a message via Yahoo to john Wesley
Thank you for your time Booooze.

Tomorow I shall tell you how I get on tonight if you wish.
__________________
Mona Lisa must of had the highway blues you can tell by the way she smiles..
john Wesley is offline   Reply With Quote
Old Jul 21st, 2006, 12:41 PM   #6
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
I think Booooze has a good idea going here. Just do an if loop to check for any drives there weren't there when the app started. Then do a file look up via the system.io.directory methods. Anyhow, i'm interested on how it works out.
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Jul 22nd, 2006, 3:34 AM   #7
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
Yeha I'm the guy booze done that for. What I'd do is use DriveInfo I think it goes soemthign like this

Imports System.IO
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Timer1.Tick
Dim di As DriveInfo = DriveInfo.GetDrives
If di.IsReady Then
(yourcodehere)
End if
End Sub
End Class

What that will do, is check if your drive is ready. It will automaticlaly do it for HDD's because they are always ready. But Like Floppy drives and CD drives arent ready unless something is in them. But thats what I'd use I'm sure there is other ways.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Old Jul 24th, 2006, 5:48 AM   #8
john Wesley
Hobbyist Programmer
 
john Wesley's Avatar
 
Join Date: May 2006
Location: United Kingdom
Posts: 119
Rep Power: 3 john Wesley is on a distinguished road
Send a message via MSN to john Wesley Send a message via Yahoo to john Wesley
thanks for all your input on this matter and Bigguy I may try it your way later so that it only looks for removables, as that's my main idea. However I did write my code for this procedure over the weekend, and it works quite well.

I should of thought on and brought it with me this morning, but alas.
I will post it tomorow though if anyone is at all interested in seeing it.
__________________
Mona Lisa must of had the highway blues you can tell by the way she smiles..
john Wesley is offline   Reply With Quote
Old Jul 24th, 2006, 10:49 AM   #9
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
I want to see it Trying to collect all the code I can and save it, so I can give it to other people, just like I did for you Saves me having to google stuff constantly
Booooze is offline   Reply With Quote
Old Jul 25th, 2006, 4:15 PM   #10
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
I'd like also, please.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware installation guide for Linux beginners coldDeath Coder's Corner Lounge 104 Jul 29th, 2007 5:40 AM
Stupid Windows, stupid DVD-RW drive Prm753 Coder's Corner Lounge 9 Jan 21st, 2006 8:26 PM
Linked list insertion at the tail elford Java 9 Jan 7th, 2006 10:04 AM
Second Hard Drive Issues... ViOLATiON Coder's Corner Lounge 2 Dec 31st, 2005 1:45 AM
minimizing hard drive activity? chepfaust Coder's Corner Lounge 3 Mar 25th, 2005 11:49 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC