Click here to Skip to main content
15,917,321 members
Please Sign up or sign in to vote.
4.60/5 (5 votes)
See more:
I am trying to create an application where, if new drive has been detected by the windows operating system, an event on the application is triggered.

Although what i was planning to do is the application to check for new drives in a given time interval but seems like that is not the appropriate thing to do.

Any suggestions?
Posted

You can use from System.Management ManagementEventWatcher, WqlEventQuery classes.
WqlEventQuery object will have Condition = @"TargetInstance ISA ""Win32_USBControllerdevice""" for USB drives and similar for other types of drives.
Subscribe to EventArrived event of ManagementEventWatcher object.
 
Share this answer
 
Try responding to the WM_DEVICECHANGE[^] window message. A WParam value of DBT_DEVICEARRIVAL[^] should indicate a new cd/usb drive.

Will probably only work if you have auto insert notification turned on for the drive.

[Edit: Oops, should have hit refresh before posting. I agree with Luc]

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900