namespace WmiExample { using System; using System.Management; using System.Diagnostics; using System.ComponentModel; /// <summary> /// </summary> public class WmiChangeEventTester { /// <summary> /// Initializes a new instance of the <see cref="WmiChangeEventTester" /> class. /// </summary> public WmiChangeEventTester() { try { // Your query goes below; "KeyPath" is the key in the registry that you // want to monitor for changes. Make sure you escape the \ character. WqlEventQuery query = new WqlEventQuery( "SELECT * FROM RegistryValueChangeEvent WHERE " + "Hive = 'HKEY_USERS'" + @"AND KeyPath = 'args[1]\\Software\\Yahoo\\pager\\profiles\\args[2]\\Custom Msgs' AND ValueName='1_W'"); ManagementEventWatcher watcher = new ManagementEventWatcher(query); Console.WriteLine("Waiting for Yahoo! Messenger to change status..."); // Set up the delegate that will handle the change event. watcher.EventArrived += new EventArrivedEventHandler(HandleEvent); // Start listening for events. watcher.Start(); // Do something while waiting for events. In your application, // this would just be continuing business as usual. System.Threading.Thread.Sleep(100000000); // Stop listening for events. watcher.Stop(); } catch (ManagementException managementException) { Console.WriteLine("An error occurred: " + managementException.Message); } } /// <summary> /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void HandleEvent(object sender, EventArrivedEventArgs e) { Console.WriteLine("Yahoo! Messenger status change detected."); Process myProcess = new Process(); myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.FileName = "PimpToolStatusExtractor.exe"; myProcess.StartInfo.CreateNoWindow = false; myProcess.Start(); } /// <summary> /// </summary> static void Main(string[] args) { // In my opinion here is where i have to set the args but will al the respect i don't know how WmiChangeEventTester receiveEvent = new WmiChangeEventTester(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)