Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 14, 2015 20:21
Show Gist options
  • Select an option

  • Save SteveGilham/7706ec7ce6c25809f58d to your computer and use it in GitHub Desktop.

Select an option

Save SteveGilham/7706ec7ce6c25809f58d to your computer and use it in GitHub Desktop.
import clr
clr.AddReference("System.Management")
from System.Management import *
from System import Console
def EvLogEventArrived(sender, e):
##Get the Event object and display it
for pd in e.NewEvent.Properties:
Console.WriteLine("{0} = {1}", pd.Name, pd.Value)
scope = ManagementScope("root\\default");
q = WqlEventQuery();
q.EventClassName = "RegistryValueChangeEvent"
q.Condition = "Hive='HKEY_LOCAL_MACHINE' and KeyPath='Software\\\\RavnaAndTines'"+
" and ValueName='my key'";
w = ManagementEventWatcher(scope, q)
try:
w.EventArrived += EventArrivedEventHandler(EvLogEventArrived)
w.Start()
Console.ReadLine() ## Block this thread, keeping the app active
##and letting the event be handled on a system thread
w.Stop()
finally:
w.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment