Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created February 18, 2018 03:47
Show Gist options
  • Save arman-hpp/ac13912ea81962dfc5ea3049806eb2f7 to your computer and use it in GitHub Desktop.
Save arman-hpp/ac13912ea81962dfc5ea3049806eb2f7 to your computer and use it in GitHub Desktop.
Detect Volume
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent");
watcher.EventArrived += Watcher_EventArrived;
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();
private static void Watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
var driveName = e.NewEvent.Properties["DriveName"].Value.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment