locked
SecurityException when Accessing Registry as SYSTEM RRS feed

  • Question

  • Hi,

    I've been working on a C# project which makes a snapshot of the registry and tracks changes every once in a while.

    I am making use of the Registry.OpenSubKey method to recursively get all the keys and put them in a dictionary. From which, I realized that there were issues with regards to permissions of several registry entries.

    Thus, I decided to run the application under SYSTEM (not just right click "run as administrator"). There are less SecurityExceptions but they still do appear. 

    ERROR:System.Security.SecurityException: Requested registry access is not allowe
    d.
       at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
       at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
       at RegistryChecker.RegistryLogic.RegProcessor.Read(RegistryKey root, IDiction
    ary`2 values) in c:\Users\mask\Documents\Visual Studio 2012\Projects\RegistryC
    hecker\RegistryChecker\RegistryLogic\RegProcessor.cs:line 89
    The Zone of the assembly that failed was:
    MyComputer

    It would be nice if someone could let me know why this exception is still coming up - I am puzzled as SYSTEM should be the most privileged? Does it have to do with the app privileges? Thanks!

     Console.WriteLine(System.Security.Principal.WindowsIdentity.GetCurrent().Name);

    returns "NT AUTHORITY/SYSTEM".

    The code that calls is as follows:

      foreach (var child in root.GetSubKeyNames())
                {
                    try
                    {
                        using (var childKey = root.OpenSubKey(child,false))
                        {
                             //DO STUFF
                        }
                    }
                    catch (Exception e)
                    { 
                        Console.WriteLine("ERROR:" + e);
                        Console.WriteLine("ROOT:"+root);
                        Console.ReadLine();
    
                    }
                }            

    Thank you very much!


    Wednesday, July 24, 2013 11:25 PM

All replies

  • What key did it fail on? If it's in your post I missed it...

    Phil Wilson

    Thursday, August 1, 2013 6:32 PM