0

Is there any way, using c#, to monitor which registry key has been added by a certain process? the important thing for me is to know the key name (path) and not just the fact that a key has been added. thanks

Sagi
  • 43
  • 3

1 Answers1

0

In my humble opinion, you cannot do this in C# only.

However, I can guide you to a solution (but it is quite advanced, though)

Registery is handled by winapi calls (which are native functions). For instance, one of them is:

[DllImport("advapi32.dll", CharSet = CharSet.Auto, BestFitMapping = false)]
internal static int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, string lpData, int cbData);

Thus, knowing when a process sets a registry value is equivalent to know when this function is called.

You can inject a process and "hack" a function (i.e. replace an existing function with your own implementation) using easy hook.

Your solution would be to use this library, hook the process you want and replace RegSetValueEx (in advapi32.dll) with a custom implementation that would only forward the call to the real implementation, and notify you when needed.

Olivier
  • 5,578
  • 2
  • 31
  • 46
  • Thanks for the answer, it took me a step forward. – Sagi Nov 22 '13 at 21:51
  • suppose I want to create an application that monitor when the function RegSetValueEx is been triggered and which parameters it gets, how can I do that ? – Sagi Nov 22 '13 at 21:56