Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 217787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:41:24+00:00 2026-05-11T18:41:24+00:00

I’m a newbie to WMI and I need to implement RegistryValueChangeEvent in a C#

  • 0

I’m a newbie to WMI and I need to implement RegistryValueChangeEvent in a C# service.

I need an event handler that gets triggered each time any one of a set of registry values is changed. I want behavior similar to the FileSystemWatcher class’s Changed event, but for registry values.

If there’s some other technique I could use to accomplish the same task, I’d appreciate that as well. My minimum requirement is that it be a better solution than what I have now: polling every 20 seconds and comparing the registry value with the last result.

Please provide example code in your answer. If I can get an example for watching just one registry value, that would be fine.

I need a solution in .Net 2.0

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:41:24+00:00Added an answer on May 11, 2026 at 6:41 pm

    WMI can sometimes be interesting to work with…I think I understand your question, so take a look at the code snippet below and let me know if it’s what you’re looking for.

    // --------------------------------------------------------------------------------------------------------------------- 
    // <copyright file="Program.cs" company="">
    //   
    // </copyright>
    // <summary>
    //   Defines the WmiChangeEventTester type.
    // </summary>
    // ---------------------------------------------------------------------------------------------------------------------
    namespace WmiExample
    {
        using System;
        using System.Management;
    
        /// <summary>
        /// </summary>
        public class WmiChangeEventTester
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="WmiChangeEventTester"/> class.
            /// </summary>
            public WmiChangeEventTester()
            {
                try
                {
                    // Your query goes below; "KeyPath" is the key in the registry that you
                    // want to monitor for changes. Make sure you escape the \ character.
                    WqlEventQuery query = new WqlEventQuery(
                         "SELECT * FROM RegistryValueChangeEvent WHERE " +
                         "Hive = 'HKEY_LOCAL_MACHINE'" +
                         @"AND KeyPath = 'SOFTWARE\\Microsoft\\.NETFramework' AND ValueName='InstallRoot'");
    
                    ManagementEventWatcher watcher = new ManagementEventWatcher(query);
                    Console.WriteLine("Waiting for an event...");
    
                    // Set up the delegate that will handle the change event.
                    watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
    
                    // Start listening for events.
                    watcher.Start();
    
                    // Do something while waiting for events. In your application,
                    // this would just be continuing business as usual.
                    System.Threading.Thread.Sleep(100000000);
    
                    // Stop listening for events.
                    watcher.Stop();
                }
                catch (ManagementException managementException)
                {
                    Console.WriteLine("An error occurred: " + managementException.Message);
                }
            }
    
            /// <summary>
            /// </summary>
            /// <param name="sender">
            /// The sender.
            /// </param>
            /// <param name="e">
            /// The e.
            /// </param>
            private void HandleEvent(object sender, EventArrivedEventArgs e)
            {
                Console.WriteLine("Received an event.");
                // RegistryKeyChangeEvent occurs here; do something.
            }
    
            /// <summary>
            /// </summary>
            public static void Main()
            {
                // Just calls the class above to check for events...
                WmiChangeEventTester receiveEvent = new WmiChangeEventTester();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.