|
using System;
using System.Collections.Generic;
using System.Management;
using System.Text;
using Microsoft.Win32;
namespace RegistryMonitor
{
public class RegistryKeyChange : RegistryChangeBase
{
#region Constants
private const string queryString = "SELECT * FROM RegistryKeyChangeEvent WHERE Hive = '{0}' AND ({1})";
#endregion Constants
#region Static Fields
private static string HiveLocation = "KeyPath";
#endregion Static Fields
#region Constructors
public RegistryKeyChange(string Hive, string KeyPath)
: this(Hive, new List<string>(new string[] { KeyPath }))
{ }
public RegistryKeyChange(RegistryKey Hive, string KeyPath)
: this(Hive.Name, KeyPath)
{
}
public RegistryKeyChange(string Hive, List<string> KeyPathCollection)
: base(Hive, KeyPathCollection)
{
this.Query.QueryString = BuildQueryString(Hive, KeyPathCollection);
this.EventArrived += new EventArrivedEventHandler(RegistryKeyChange_EventArrived);
}
public RegistryKeyChange(RegistryKey Hive, List<string> KeyPathCollection)
: this(Hive.Name, KeyPathCollection)
{
}
#endregion Constructors
#region Private Methods
private string BuildQueryString(string Hive, List<string> KeyPathCollection)
{
string ORString = RegistryChangeBase.BuildOrString(KeyPathCollection);
string FormattedOR = string.Format(ORString, HiveLocation);
return string.Format(queryString, Hive, FormattedOR);
}
private void RegistryKeyChange_EventArrived(object sender, EventArrivedEventArgs e)
{
RegistryKeyChangeEvent RegValueChange = new RegistryKeyChangeEvent(e.NewEvent);
OnRegistryKeyChanged(RegValueChange);
}
protected virtual void OnRegistryKeyChanged(RegistryKeyChangeEvent RegValueChange)
{
if (RegistryKeyChanged != null)
{
RegistryKeyChanged(this, new RegistryKeyChangedEventArgs(RegValueChange));
}
}
#endregion Private Methods
#region Events
public event EventHandler<RegistryKeyChangedEventArgs> RegistryKeyChanged;
#endregion Events
}
public class RegistryKeyChangedEventArgs : EventArgs
{
private RegistryKeyChangeEvent data;
public RegistryKeyChangeEvent RegistryKeyChangeData
{
get
{
return data;
}
}
public RegistryKeyChangedEventArgs(RegistryKeyChangeEvent Data)
{
data = Data;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.