I want a notification when a specific RegistryKey in HKEY_CURRENT_USER
is changed.
So far I tried this via WMI
with no success:
var
Uploaded to pastbin a nice class that does it. Hope it fits your needs.
http://www.csharp.pastebin.com/0reFh6v2
I finally solved the problem and got the WMI query version to work:
var currentUser = WindowsIdentity.GetCurrent();
var query = new WqlEventQuery(string.Format(
"SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_USERS' AND KeyPath='{0}\\\\{1}' AND ValueName='{2}'",
currentUser.User.Value, keyPath.Replace("\\","\\\\"), valueName));
_watcher = new ManagementEventWatcher(query);
_watcher.EventArrived += (sender, args) => KeyValueChanged();
_watcher.Start();
I found this "hack" at http://www.codeproject.com/Messages/2844468/Monitoring-HKEY_CURRENT_USER.aspx