有没有办法记录进程读/写的所有注册表值,类似于Process Monitor的工作?
答案 0 :(得分:0)
在.NET中处理WMI事件 ---为了处理.NET中的WMI事件,我们可以使用System.Management命名空间中的类。例如,这是一段代码 由WMI Code Creator制作:
using System; using System.Management; using System.Windows.Forms; namespace WMISample { public class WMIReceiveEvent { public static void Main() { try { //Construct the query. Keypath specifies the key in the registry to watch. //Note the KeyPath should be must have backslashes escaped. Otherwise //you will get ManagementException. WqlEventQuery query = new WqlEventQuery( "SELECT * FROM RegistryKeyChangeEvent WHERE " + "Hive = 'HKEY_LOCAL_MACHINE'" + @"AND KeyPath = 'SOFTWARE\\Microsoft\\.NETFramework'"); ManagementEventWatcher watcher = new ManagementEventWatcher(query); Console.WriteLine("Waiting for an event..."); ManagementBaseObject eventObj = watcher.WaitForNextEvent(); Console.WriteLine("{0} event occurred.", eventObj["__CLASS"]); // Cancel the event subscription watcher.Stop(); return; } catch(ManagementException err) { MessageBox.Show("An error occurred while trying to receive an event: " + err.Message); } } } }