Registry Monitoring for Service

I would like to know if there is a Registry Monitoring Available.

I am using External App to change setting and such in the Service app by changing the value in Registry.

But somehow I must be able to signal the service to load the new setting.

Please let me know how this is possible.



Answer this question

Registry Monitoring for Service

  • norax

    There are 2 ways to solve this problem:

    1. Use a special registry key where your service is listening too. For example your external application changes some settings then is also has to change the special registry key from 0 to 1. So your service recognizes this and is able to load the new settings.

    2. You can use a TcpChannel to push the settings to the service or to trigger it on to have a look at the registry.

    I hope this helps.

  • Stephanie Barulic

    You can try polling(checking the status of) the Registry at regular intervals using Timer class and change the settings accordingly.

    However, there might be a better way. I won't take guarantee on this solution being the best :)

  • Mo_Fya

    Check out Sysinternal's RegMon. Depending on which version of Windows you run it on, it uses different techniques to monitor the registry. On WinXP, it loads a device driver that hooks the registry related system calls, allowing them to monitor activity before forwarding it to the appropriate Win32 function.

    http://www.sysinternals.com/Utilities/Regmon.html

    Although they don't provide source, they do provide copious links to articles on how to enable this type of functionality.

    Avoiding a polling mechanism will involve some fairly low-level code that would require fairly high rights to operate. You may want to go with the suggested polling approach because the consequences of a bug in polling code is less severe than a bug in a kernel-level device driver.

  • Vikas Bindra

    Thanks guys for all your suggestion.

    abhi.pandey:
    Your suggestion may be the easyest one, but it can annoy the user if he has to wait few sec. until the new settings apply.

    James Kovacs:
    althought this does seem to work, it doesn't solve my problem, the way regmon works is that it replaces a kernel function with it's own, this may be too difficult for me to program :-/

    Norbert Eder:
    Your first example may work for me, but constantly checking registry... doesnt it slow the computer down I might add this befour I do something in the app resolving no wait time.

    I am not quite sure what you mean by TcpChannel, I have never heard it befour...


    Thanks again guys, I will start working as soon as I can :)


  • Pimpom

    I should have been clearer. My point wasn't to suggest that hooking a kernel level function was a good idea for your application. More that if you want to monitor the registry, you'll have to hook a kernel level function. (i.e. Very hard.) I like Norbert's suggestion about the TcpChannel. i.e. Have notification of your config changes relayed via another mechanism (i.e. TcpChannel). If someone hand-edits the registry, the changes won't be picked up, but do you require this

    WRT TcpChannel - This is one of the classes in System.Net that is usually used for TCP network communication, but you can use it for interprocess communication too. The Genghis Group used this technique for ensuring only a single instance of an app is running and passing all open document requests to the running instance. Take a look at the SingleInstance sample and how InitialInstanceActivator is implemented. This should give you a good headstart on implementing TcpChannel for IPC (inter-process communication).

    Another option in a similar vein is to use the FileSystemWatcher class. Create a file in a known location and point FileSystemWatcher at it from your service. When the registry is updated by your config app, simply update the file and the service will be notified that the file has been modified (i.e. time to reload registry setting).


  • Registry Monitoring for Service