Event when removable drived added/removed

Is there an event that I can subscribe to, to get notified when a removable 
drive is added or removed?

Thanks
LS 

0
Lloyd
12/28/2009 2:59:47 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

4 Replies
976 Views

Similar Articles

[PageSpeed] 24

"Lloyd Sheen" <a@b.c> wrote in
news:#Xols58hKHA.3792@TK2MSFTNGP02.phx.gbl: 

> Is there an event that I can subscribe to, to get notified when a
> removable drive is added or removed?

Assume all removables are USB today. :-)

Start here:
http://www.codeproject.com/KB/system/DriveDetector.aspx

This is a wrapper project for the Windows libraries that work with these 
drives.

Peace and Grace,


-- 
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
|      Think outside the box!             |
*******************************************
0
Gregory
12/28/2009 4:39:01 PM
"Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message 
news:Xns9CEF6C0EDBB1Agbworld@207.46.248.16...
> "Lloyd Sheen" <a@b.c> wrote in
> news:#Xols58hKHA.3792@TK2MSFTNGP02.phx.gbl:
>
>> Is there an event that I can subscribe to, to get notified when a
>> removable drive is added or removed?
>
> Assume all removables are USB today. :-)
>
> Start here:
> http://www.codeproject.com/KB/system/DriveDetector.aspx
>
> This is a wrapper project for the Windows libraries that work with these
> drives.
>
> Peace and Grace,
>
>
> -- 
> Gregory A. Beamer (MVP)
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> |      Think outside the box!             |
> *******************************************

Thanks for the guidance.  Guess I should have said I was using WPF.  I am 
trying to use the code you pointed out in conjunction with some code I found 
for overriding the winproc in WPF.  So far no joy.

Thanks
LS 

0
Lloyd
12/28/2009 6:01:20 PM
"Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message 
news:Xns9CEF6C0EDBB1Agbworld@207.46.248.16...
> "Lloyd Sheen" <a@b.c> wrote in
> news:#Xols58hKHA.3792@TK2MSFTNGP02.phx.gbl:
>
>> Is there an event that I can subscribe to, to get notified when a
>> removable drive is added or removed?
>
> Assume all removables are USB today. :-)
>
> Start here:
> http://www.codeproject.com/KB/system/DriveDetector.aspx
>
> This is a wrapper project for the Windows libraries that work with these
> drives.
>
> Peace and Grace,
>
>
> -- 
> Gregory A. Beamer (MVP)
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> |      Think outside the box!             |
> *******************************************

For those who may have read the post I will post the code that I came up 
with (so far) that I will use to detect the changes.

First in the window event SourceInitialized add the following code:

 Private Sub MainWindow_SourceInitialized(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.SourceInitialized
  Dim src As HwndSource = HwndSource.FromHwnd(New 
WindowInteropHelper(Me).Handle)
  src.AddHook(New HwndSourceHook(AddressOf WndProc))
 End Sub

Then add the code of the winProc that you wish to handle:

 Public Function WndProc(ByVal hwnd As IntPtr, ByVal msg As Integer, ByVal 
wParam As IntPtr, ByVal lParam As IntPtr, ByRef handled As Boolean) As 
IntPtr
  If msg = WM_DEVICECHANGE Then  ' you will have to put either a CONST in 
your code or hard code this value which is 537
   If deviceChanged Is Nothing Then
    deviceChanged = New DispatcherTimer
    AddHandler deviceChanged.Tick, AddressOf deviceChanged_Tick
    deviceChanged.Interval = TimeSpan.FromMilliseconds(1000)
    deviceChanged.Start()
   Else
    deviceChanged.Stop()
    deviceChanged.Start()
   End If
  End If
  Return IntPtr.Zero
 End Function


I am doing the code in a timer event so that it will not interfer with the 
app.  In my app this is fine and you can fine tune the dispatch timer 
interval if needed.  I found that a second was just fine since this event 
takes a certain amount of time.

Then there is the dispatchertimer code:

 Private deviceChanged As DispatcherTimer

 Private Sub deviceChanged_Tick(ByVal sender As Object, ByVal e As 
System.EventArgs)
  deviceChanged.Stop()
  'Debug.WriteLine("A device has changed")
  ' this is where I will put code in to handle the add/remove of a device
  deviceChanged = Nothing
 End Sub

In docs it says that the wParam  should contain different values if the 
device is added or removed but I found that the parameter was the same for 
each occasion.  The wierd code in the wndProc about setting up the timer 
occurs because there is about 7 or eight messages sent so I am just handling 
the last one.

Thanks again for getting me on the right track and I hope the above code 
will help others.

LS 

0
Lloyd
12/28/2009 6:34:15 PM
"Lloyd Sheen" <a@b.c> wrote in news:uKyMJf#hKHA.5380@TK2MSFTNGP06.phx.gbl:

> Thanks for the guidance.  Guess I should have said I was using WPF. 

Probably, because most of use get myopic when there is no context. LOL

Peace and Grace,

-- 
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
|      Think outside the box!             |
*******************************************
0
Gregory
12/29/2009 5:00:47 PM
Reply:

Similar Artilces:

OnLoad event criteria
If have the code below in the OnLoad event which is working fine for the most part. The second line is causing a problem for cases where there is no matching record. The code is setting the value - I'd like to have it check the value first, and if it matches the value for the related field in the current form recordset, set the value, otherwise just open the form without setting the value. If CurrentProject.AllForms("AllOpen").IsLoaded Then Me.Combo1 = Forms!AllOpen!ID ' Find the record that matches the control. Dim rs As Object Set rs ...

Printing Private events/appts. on Calendars
A while ago I asked about how to stop Outlook printing private appointments or events in the calendars. Someone said to check "don't print private events" in the print screen which I did. Anyway, the calendar that gets printed, in the day that there is a private event it says "Private Event". How do I stop it from printing them altogether? I want it to appear on the calendar as nothing. ie. if there is only that event then the calendar should appear with no events for that day. Thanks ...

Remove duplicates from Sheet 2
Hi everyone, I have 2 sheets containing data Sheet 1 A1-AT623 and Sheet 2 A1-AF822. Where I already have data in Sheet 1 I would like to be able to delete (or extract to a 3rd sheet) that row in Sheet 2. If anyone could help that would be fantastic! Cheers Diddy Examples and criteria? -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett@gmail.com "Diddy" <Diddy@discussions.microsoft.com> wrote in message news:82655AA2-5EAA-4B87-809A-88F4C624A63C@microsoft.com... > Hi everyone, > > I have 2 sheets containing data > > ...

ARGH Money 2005
Well I figured out my problems with duplicated Bills, MSN Money. Apparently online data was being downloaded and merged into my local data. Each time I tried to troubleshoot the problem the data on MSN Money got worse and would then be merged with local data. My fix was opening Money with no Internet connection. THen going into Money and instructing it to delete my MSN Money data. Seems to have worked thus far. Now I realize that two features I used in Standard have been moved to the Deluxe edition. Debt Reduction Planner and Cash Forecast are gone from Standard. Not sure why since the...

Failed drive?
Hi all, For a few weeks my Laptop (Dell Inspiron 1525) had been randomly freezing, and earlier today it froze. I did what I usually do, which was restart and wait, but this time it just wouldn't turn on; it kept telling me it had failed to start correctly. After trying again and again with the system repair, with no luck, I tried safe mode, which still wouldn't work. After exploring different repairs and overviews, I kept getting; Hard drive - DST Short Test Test results: Fail Error code 2000-0142 Msg: Hard drive 1 - Self test unsuccessful. Status 79 I eventually did a ...

Error in Event Viewer event id 1023 pop3 connector, 1029, 1036, 10
Hello Exchange Administrators, I am getting these Error in Event Viewer "event id 1023 pop3 connector, 1029, 1036, 1015, 1019, 1015" on regular basis after every 15 min for every user. I need yours help to fix these errors. Also tell me why these error are logged in event viewer or cause of these errors We are using WIndoes 2003 SBS, Exchange Server 2003. Thanks you for yours help in advance. On Fri, 1 Sep 2006 11:11:01 -0700, Guri <Guri@discussions.microsoft.com> wrote: >Hello Exchange Administrators, > >I am getting these Error in Event Viewer "event id 1...

deleting events in calender
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel Email Client: pop I have inadvertently imported a weekly event into my calender. Each event seems to be logged as an individual event rather than a repeat event. I do not know how to delete it. Am trying, unsuccessfully, to show all events in one window so that I can easily select this irrelevant event, but cant display that window. Can you help me, either showing that elusive window, or how to otherwise delete MANY events. In article <59bb30c6.-1@webcrossing.JaKIaxP2ac0>, <leaest@officeformac.com> w...

Catch click event button
Hi all, I was wondering... Is it possible to "catch" a click-event on a BuildIn Offie Button? In order to execute your own VBA-code? e.g. I want to be able to catch the "Undo" button in order to execute a piece of macro code in stead of just "Undoing" only the last action. Greetz, Bert -- Neron It is possible to catch ("intercept") most built-in Word commands, as described at http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm. In this case, the macro you need to write is named EditUndo, as in Public Sub E...

4117 Event ID Error
Starting 1-29-04 we started getting 4117 error messages just like those discussed in Micrisoft's Knowledge Base Article 190084. The only thing that arcticle suggests is to update to SP 4 which is already installed on the machine. I have never seen this message before and now we are getting one every few minutes. Any help would be appreciated. Thanks Sean Seems like you have something else going on then, check out the following articles and see if these help: 126497 XADM: Limiting the Number of Recipients of a Message http://support.microsoft.com/?id=126497 230250 XFOR: Internet ...

Unable to remove password in MS Word Document
In Word 2007, I assigned a password in order to open the doc and it works fine. However now I want to remove the password and have followed the instructions from the "Demo" in Microsoft to do this. I've also followed the steps provided in this forum's replies without success. Unfortunately, when it comes time to remove the assigned password, the 'box' is greyed-out and inaccessible. Also, on the "Review Tab" the "Protect Document" box is greyed-out and inaccessible. Any thoughts? Thanks I assume that the document was c...

Removing items from worksheet by account number question
I need to remove everything that is related to one account number and so on for other account numbers is there a way to do this or a way to highlight them... Thank you. You need to tell us how the data is set out -- Bernard V Liengme Microsoft Excel MVP www.stfx.ca/people/bliengme remove caps from email "LiveUser" <LiveUser@discussions.microsoft.com> wrote in message news:35F1A01E-6859-4E14-A44D-88754251DB5B@microsoft.com... >I need to remove everything that is related to one account number and so on > for other account numbers is there a way to do this or a way t...

Hard drive - Cant access it
Advice appreciated. In brief - 500GB Maxtor External Hard drive plugged into Windows 7 pc - can read what's on the drive ok. When plugged into an XP pc however can't access it. How to be able to access it on an xp pc? More info..it belongs to a mate of mine. Its in my possession now, however, to try to sort it. A clue as to how it got like it is...friend uses it with his xp pc. A few weeks ago he said it presented with do you want to format the drive, he said yes (don't ask!)..it whirred away for a couple hours he said then stopped. He switched it on and couldn'...

Event
I have recorded a macro that I need to automatically run at 6:45am daily. How do I specify this in the code? Everything you need to know about OnTime procedures (but were afraid to ask): http://www.cpearson.com/excel/ontime.htm You'll need to have excel running for this to work. ===== Some versions of windows have scheduler programs. (Or you can get a freeware/shareware version on the web (www.shareware.com is where I look first.) Then you could have that scheduling program start an excel workbook. If you name the macro Auto_Open, then it'll run when the workbook opens. (But ...

removing multiple attachments
it seems I can't remove more than 1 attachment at a time from an e-mail. I have to right click on each one, hit remove then go to the next attachment. If I select multiple attachments, the remove, delete, cut options are grayed out and the delete key won't work. Any ideas? thanks, Larry ...

Event After the sale
Hi to all Is any way to bypass the event that after you complete the sale you get a window with the change in it, in order to go to the next sale you have either hit OK or enter because if you scan an item from that point it does not scan in and it appears to me that you can miss an item from been scanned in any way to fix this issue. Also if you have scan several items into the system and you go to del one item in the middle of the page RMS is loosing its focus and starts to scan into the next line down which deletes the items that have been scanned.I think it should go to the next ...

Adding an Item to the Main Menu
I want to add a new top level entry on the Main Menu that will run a macro. Doing so should allow me to have a menu with the new entry each time I open Excel. I've done this before under Excel 97 but when I try to do it under 2003 I run into the following problem I right click on the Main Menu and choose Customize. I then select Macro from Categories and drag a Custom Menu Item from Commands to the menu. I then rename it and assign a macro. At least, I believe this is the way I did it under 97 years ago. The menu item works just as expected. However, when I exit Excel and the...

What event when I click the record selector
I have some labels on the form would like to populate its value (they are calculated values) when I select the record selector, next, previous or last or first. What event should I write the code into? On Tue, 22 May 2007 11:01:23 +1000, "Alan T" <alanpltseNOSPAM@yahoo.com.au> wrote: >I have some labels on the form would like to populate its value (they are >calculated values) when I select the record selector, next, previous or last >or first. > >What event should I write the code into? > Well, don't use Labels for this purpose; use textboxes ...

How to I advance filter to remove rows containing partic string of text?
Is this possible? I know how to filter to include strings of text but I don't know how to filter so that rows containing a certain email address domain name are not visible in the filetered results. Many thanks if anyone's able to assist! Dave Hi one way: use a helper column with a formula like =IF(ISNUMBER(FIND("domain.com",A1)),1,0) and filter with this column >-----Original Message----- >Is this possible? > >I know how to filter to include strings of text but I don't know how >to filter so that rows containing a certain email address domain name &...

Can't read A drive
I just installed Windows xp sp3 on an older Compaq workstation. When I try to read a file on the A drive I can get the list of files on the floppy but I cant read any of the files even .txt files. I get messages like "cannot read theA:readme.txt file or in another case "the folder is invalid or corrupted" I can use notepad to write a file and then write it to the floppy and I can read the file back My objective in all this is to load windows 3.1 into the virtual machine Sun virtual Box. When I try to load the boot disk using virtual box I have the same proble...

Recurring event
Is there a way to set a meeting date and have it recurring each month, but not on a certain week or certain date of each month. My meeting happens on a Thursday in each month but not every 2nd, 3rd or 4th Thursday. Some months it is the 3rd Thursday and some it is the 4th Thursday. ...

Removing Near-Duplicate Rows, Leaving Those w/Most Data in Specific Columns
I have a spreadsheet with about 20,000 rows of data and I am trying to eliminate unnecessary rows. Columns B&C contain numbers, and columns D through AR contain text. Many rows contain identical information in columns B, C, D, E, & F, but the information in the remaining columns may differ. I would like to eliminate rows with duplicate data in columns B through F, retaining the rows with the greatest number of entries in columns G through AR. An example of what I would like to get to is shown below. BEFORE B C D E F G H I J K L Row 1 12 34 DD EE F...

Events, dear boy, events #3
Aha I pasted: Application.EnableEvents = true into the immediate window and now the code is working. I don't have an code that would have turned it off in the first place, however. Coul this be a default setting somewhere, or is just one of those thing that can happen now and then? Anyway, thanks for the solution, Bo -- Gromi ----------------------------------------------------------------------- Gromit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=92 View this thread: http://www.excelforum.com/showthread.php?threadid=27721 Just a guess. If you turn...

Adding Entries to the Standard Context Menu in Internet Explorer for all users
Hello, This MSDN article: http://msdn.microsoft.com/en-us/library/aa753589(VS.85).aspx explains how to add an entry to IE menu for the current user. I would like to add an entry to all users, but under HKLM such key does not exist. How to understand that? Is that impossible to do the same for all the users or am I missing something in here? Thank you, Claire ...

Vista indexing mapped drives
Hi, I am trying to add a network share to the locations that are indexed. i click 'Modify' and the 'Indexed Locations' window pops up, but at the bottom, 'show all locations' is greyed out. How can i index mapped drives? Thanks, Al On Fri, 19 Mar 2010 12:02:26 -0400, "AATech" <u2nyr@live.com> wrote: >Hi, > >I am trying to add a network share to the locations that are indexed. i >click 'Modify' and the 'Indexed Locations' window pops up, but at the >bottom, 'show all locations' is greyed out...

Posting events to the event viewer.
I've been using a particular method to post program events to the event viewer. It works, but there is an issue that is driving me crazy. Perhaps there is a better way or different way to accomplish what I am doing. 1) My events are listed in a file I call EventLog.mc. The events are in this file using a particular syntax. 2) Right after creating the file for the first time, or if I change the file, I run the event log compiler. by doing "mc.exe EventLog -d". This process creates a file called "EventLog.rc". 3) I directly edit my program's main .rc file. Nea...