Receive notification when RegistryKey Value was changed

后端 未结 2 568
耶瑟儿~
耶瑟儿~ 2020-12-15 13:01

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         


        
相关标签:
2条回答
  • 2020-12-15 13:20

    Uploaded to pastbin a nice class that does it. Hope it fits your needs.

    http://www.csharp.pastebin.com/0reFh6v2

    0 讨论(0)
  • 2020-12-15 13:29

    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

    0 讨论(0)
提交回复
热议问题