RegistryMonitor Как проверить изменённое действие?
Из примера RegistryMonitor для слежки за изменением действий в реестре.
Как можно проверить определённое действие, допустим если что-то добавилось в реестр, уведомить что что-то добавилось или наоборот удалилось и.т.д.
static RegistryMonitor monitor;
private void OnRegChanged(object sender, EventArgs e)
{
Console.WriteLine("Что-то изменилось в реестре");
// Можно ли как-то здесь организовать проверку по типу ниже:
// if (monitor == keyDelete)
// {
// Удалился ключ в реестре
// }
// else
// {
// удалился раздел в реестре и.т.п
// }
}
static void Main()
{
monitor = new RegistryMonitor(RegistryHive.CurrentUser, "Environment");
monitor.RegChanged += new EventHandler(OnRegChanged);
monitor.Start();
while(true);
monitor.Stop();
}
Up.. Если кто-то знает подскажите)
Я вроде как бы нащупал что-то нужное:
/// <summary>
/// Filter for notifications reported by <see cref="RegistryMonitor"/>.
/// </summary>
[Flags]
public enum RegChangeNotifyFilter
{
/// <summary>Notify the caller if a subkey is added or deleted.</summary>
Key = 1,
/// <summary>Notify the caller of changes to the attributes of the key,
/// such as the security descriptor information.</summary>
Attribute = 2,
/// <summary>Notify the caller of changes to a value of the key. This can
/// include adding or deleting a value, or changing an existing value.</summary>
Value = 4,
/// <summary>Notify the caller of changes to the security descriptor
/// of the key.</summary>
Security = 8,
}
Дальше пробую сделать проверку внутри
private void OnRegChanged(object sender, EventArgs e)
{
if (monitor.RegChangeNotifyFilter == RegChangeNotifyFilter.Value)
{
Console.WriteLine("Изменилось значение в реестре"); // Это работает
}
if (monitor.RegChangeNotifyFilter == RegChangeNotifyFilter.Key)
{
Console.WriteLine("Изменился раздел в реестре"); // Это нет
}
}
Если изменить какое-то значение в ветке реестра то он это замечает, а если раздел то не видет.