Registry equivalent of FileSystemWatcher class

Posted on 2005-05-13
Last Modified: 2012-05-05
I am using a windows service to monitor a directory but I also need to monitor a registry value.

Is there a way to monitor a change in a particular registry value in .NET similar to monitoring a file or directory with FileSystemWatcher?

If there is no .NET class that does this, can you give an example on how to do this?  
Question by:big_lew
    1 Comment
    LVL 37

    Accepted Solution

    you would just write a simple class that had a thread that checked the value and raised an event when it changed

          public class RegistryWatcher
                public delegate void HandleRegistryChange(object sender, string key);
                public event HandleRegistryChange RegistryChanged;

                protected void OnRegistryChanged(object value)
                      if(this.RegistryChanged != null)
                            this.RegistryChanged(this, key);

                private void Loop()
                      obj val;
                            val = GetRegistryValue();
                            if(val != lastval)
                                  lastval = val;

                public void Start()
                      ThreadStart ts = new ThreadStart(this.Loop);
                      Thread t = new Thread(ts);

                public void RegistryWatcher() { }


    is an example (just implement GetRegistryValue) and it will produce events when it changes ...

    Naturally it would be easy to have it watch 100 or 1000 keys if passed in (just another for loop)



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now