Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#

Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET

Rate me:
Please Sign up or sign in to vote.
4.83/5 (17 votes)
14 Nov 2008CPOL6 min read 129.8K   4.5K   70  
How to receive asynchronous events about Registry changes, using WMI.
namespace RegistryMonitorSampleApplication
{
    partial class MainForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Windows.Forms.Label label3;
            System.Windows.Forms.Label label2;
            System.Windows.Forms.Label label1;
            this.btnStart = new System.Windows.Forms.Button();
            this.lsbDisplay = new System.Windows.Forms.ListBox();
            this.grpOptions = new System.Windows.Forms.GroupBox();
            this.chkTreeChange = new System.Windows.Forms.CheckBox();
            this.chkKeyChange = new System.Windows.Forms.CheckBox();
            this.txbValueName = new System.Windows.Forms.TextBox();
            this.chkValueChange = new System.Windows.Forms.CheckBox();
            this.txbKeyPath = new System.Windows.Forms.TextBox();
            this.cmbHive = new System.Windows.Forms.ComboBox();
            label3 = new System.Windows.Forms.Label();
            label2 = new System.Windows.Forms.Label();
            label1 = new System.Windows.Forms.Label();
            this.grpOptions.SuspendLayout();
            this.SuspendLayout();
            // 
            // label3
            // 
            label3.AutoSize = true;
            label3.Location = new System.Drawing.Point(371, 67);
            label3.Name = "label3";
            label3.Size = new System.Drawing.Size(208, 26);
            label3.TabIndex = 14;
            label3.Text = "ValueName: (Must be specified when\r\nsubscribing to RegistryValueChangeEvent)";
            // 
            // label2
            // 
            label2.AutoSize = true;
            label2.Location = new System.Drawing.Point(7, 67);
            label2.Name = "label2";
            label2.Size = new System.Drawing.Size(338, 26);
            label2.TabIndex = 12;
            label2.Text = "KeyPath: (One per line. If you subscirbe to RegistryValueChangeEvent\r\nonly the fi" +
                "rst one will be used. KeyPath must be escaped)";
            // 
            // label1
            // 
            label1.AutoSize = true;
            label1.Location = new System.Drawing.Point(7, 20);
            label1.Name = "label1";
            label1.Size = new System.Drawing.Size(32, 13);
            label1.TabIndex = 11;
            label1.Text = "Hive:";
            // 
            // btnStart
            // 
            this.btnStart.Location = new System.Drawing.Point(2, 195);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(107, 23);
            this.btnStart.TabIndex = 10;
            this.btnStart.Text = "Start Monitoring";
            this.btnStart.UseVisualStyleBackColor = true;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // lsbDisplay
            // 
            this.lsbDisplay.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lsbDisplay.FormattingEnabled = true;
            this.lsbDisplay.Location = new System.Drawing.Point(0, 224);
            this.lsbDisplay.Name = "lsbDisplay";
            this.lsbDisplay.Size = new System.Drawing.Size(675, 212);
            this.lsbDisplay.TabIndex = 11;
            // 
            // grpOptions
            // 
            this.grpOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.grpOptions.Controls.Add(this.chkTreeChange);
            this.grpOptions.Controls.Add(this.chkKeyChange);
            this.grpOptions.Controls.Add(this.txbValueName);
            this.grpOptions.Controls.Add(label3);
            this.grpOptions.Controls.Add(this.chkValueChange);
            this.grpOptions.Controls.Add(this.txbKeyPath);
            this.grpOptions.Controls.Add(label2);
            this.grpOptions.Controls.Add(label1);
            this.grpOptions.Controls.Add(this.cmbHive);
            this.grpOptions.Location = new System.Drawing.Point(2, 1);
            this.grpOptions.Name = "grpOptions";
            this.grpOptions.Size = new System.Drawing.Size(673, 188);
            this.grpOptions.TabIndex = 0;
            this.grpOptions.TabStop = false;
            this.grpOptions.Text = "Options";
            // 
            // chkTreeChange
            // 
            this.chkTreeChange.AutoSize = true;
            this.chkTreeChange.Location = new System.Drawing.Point(428, 13);
            this.chkTreeChange.Name = "chkTreeChange";
            this.chkTreeChange.Size = new System.Drawing.Size(213, 17);
            this.chkTreeChange.TabIndex = 20;
            this.chkTreeChange.Text = "Subscribe to RegistryTreeChangeEvent";
            this.chkTreeChange.UseVisualStyleBackColor = true;
            // 
            // chkKeyChange
            // 
            this.chkKeyChange.AutoSize = true;
            this.chkKeyChange.Location = new System.Drawing.Point(213, 14);
            this.chkKeyChange.Name = "chkKeyChange";
            this.chkKeyChange.Size = new System.Drawing.Size(209, 17);
            this.chkKeyChange.TabIndex = 19;
            this.chkKeyChange.Text = "Subscribe to RegistryKeyChangeEvent";
            this.chkKeyChange.UseVisualStyleBackColor = true;
            // 
            // txbValueName
            // 
            this.txbValueName.Location = new System.Drawing.Point(374, 96);
            this.txbValueName.Multiline = true;
            this.txbValueName.Name = "txbValueName";
            this.txbValueName.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.txbValueName.Size = new System.Drawing.Size(287, 86);
            this.txbValueName.TabIndex = 15;
            // 
            // chkValueChange
            // 
            this.chkValueChange.AutoSize = true;
            this.chkValueChange.Location = new System.Drawing.Point(428, 35);
            this.chkValueChange.Name = "chkValueChange";
            this.chkValueChange.Size = new System.Drawing.Size(218, 17);
            this.chkValueChange.TabIndex = 21;
            this.chkValueChange.Text = "Subscribe to RegistryValueChangeEvent";
            this.chkValueChange.UseVisualStyleBackColor = true;
            // 
            // txbKeyPath
            // 
            this.txbKeyPath.Location = new System.Drawing.Point(10, 96);
            this.txbKeyPath.Multiline = true;
            this.txbKeyPath.Name = "txbKeyPath";
            this.txbKeyPath.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.txbKeyPath.Size = new System.Drawing.Size(313, 86);
            this.txbKeyPath.TabIndex = 13;
            // 
            // cmbHive
            // 
            this.cmbHive.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbHive.FormattingEnabled = true;
            this.cmbHive.Items.AddRange(new object[] {
            "HKEY_LOCAL_MACHINE",
            "HKEY_USERS ",
            "HKEY_CURRENT_CONFIG"});
            this.cmbHive.Location = new System.Drawing.Point(10, 36);
            this.cmbHive.Name = "cmbHive";
            this.cmbHive.Size = new System.Drawing.Size(172, 21);
            this.cmbHive.TabIndex = 10;
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(675, 440);
            this.Controls.Add(this.grpOptions);
            this.Controls.Add(this.lsbDisplay);
            this.Controls.Add(this.btnStart);
            this.Name = "MainForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Registry Monitor";
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.grpOptions.ResumeLayout(false);
            this.grpOptions.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button btnStart;
        private System.Windows.Forms.ListBox lsbDisplay;
        private System.Windows.Forms.GroupBox grpOptions;
        private System.Windows.Forms.TextBox txbValueName;
        private System.Windows.Forms.TextBox txbKeyPath;
        private System.Windows.Forms.ComboBox cmbHive;
        private System.Windows.Forms.CheckBox chkValueChange;
        private System.Windows.Forms.CheckBox chkTreeChange;
        private System.Windows.Forms.CheckBox chkKeyChange;

    }
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Georgia Georgia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions