0

What I want to achieve

I have a console application that runs a file system watcher for USB drives. When I try to eject device, I receive prompt message notifying device is in use.
I want to capture that request, close the file system watcher and resume the USB eject process. I don't want eject notification (i.e; Event fired after USB is removed).

What I've tried

I've Tried These Method 1 Method 2 Method 3

The method 1 is a winform application, it works but It would be great if I could do it in a Console application.

In method 2 event is fired only after USB is removed, but I want to capture the event before it is ejected.

Method 3 is a windows service application, I can't get the DriveID (eg: F) in this.

Sorry for any mistakes. Thanks for the help.

Community
  • 1
  • 1
Karthik
  • 31
  • 1
  • 1
  • 7
  • Hi take a look at the following SO answer. [here](https://stackoverflow.com/questions/52598371/catch-usb-plug-and-unplug-event-system-invalidcastexception?answertab=active#tab-top) – Terblanche Daniel Oct 24 '19 at 12:57
  • @TerblancheDaniel Thanks for the response, I've tried this in [Method 1](https://www.codeproject.com/Articles/18062/Detecting-USB-Drive-Removal-in-a-C-Program) and it works, I was hoping to do the same in a console application where I don't have a Message Handler (WinForms) or Service Handler (WinService) which is needed to use the RegisterDeviceNotification – Karthik Oct 24 '19 at 13:17

0 Answers0