Quantcast
Channel: Questions in topic: "dll"
Viewing all articles
Browse latest Browse all 706

Error in using WMI to catch logical drives events

$
0
0
Hi everyone, I'm trying to catch Win32 events to detect plugged in drives such as usb and external hard disks. I've imported the System.Management.dll from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ and then wrote the script like this var watcher = new ManagementEventWatcher(); var query = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent"); watcher.EventArrived += (s, e) => { //log event properties }; watcher.Query = query; watcher.Start(); However, this raises an error when the thread starts: NullReferenceException: Object reference not set to an instance of an object System.Management.ThreadDispatch.Start () (at :0) System.Management.ManagementScope.Initialize () (at :0) System.Management.ManagementObjectSearcher.Initialize () (at :0) System.Management.ManagementObjectSearcher.Get () (at :0) Does someone have any experience with this? The same code works when inside a simple console application.

Viewing all articles
Browse latest Browse all 706

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>