I get this error:
Unhandled exception: System.Runtime.InteropServices.COMException (0x80042001): Exception from HRESULT: 0x80042001 in System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal (Int32 errorCode, IntPtr errorInfo) in System.Mangram.Mangram. .Main (String [] args) in {somedir} \ Program.cs: line 16
And here is my C # console application that I use to view the registry:
using System;
using System.Management;
namespace MyNamespace
{
class Program
{
static void Main(string[] args)
{
var watcher = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM RegistryTreeChangeEvent"));
var handler = new MyHandler();
watcher.EventArrived += handler.Arrived;
watcher.Start();
while (handler.EventHasntFiredYet)
{
}
watcher.Stop();
}
public class MyHandler
{
public bool EventHasntFiredYet;
public MyHandler()
{
EventHasntFiredYet = true;
}
public void Arrived(object sender, EventArrivedEventArgs e)
{
var propertyDataCollection = e.NewEvent.Properties;
foreach (var p in propertyDataCollection)
{
Console.WriteLine("{0} -- {1}",p.Name,p.Value);
}
EventHasntFiredYet = false;
}
}
}
}
I'm trying to just watch the registry for changes. Does anyone have any suggestions as to why this fails?
source
share