SilverX
SilverX

Reputation: 1519

Registry access exception problem

I'm currently building a registry explorer, mostly because I want to support some much better searching operations. Like 'find all' and regular expressions. One problem I'm facing is that some keys throw a security exception when opening. I HAVE TRIED running the app with administrator priviledges, my user account is an administrator also. I embedded a manifest with "requireAdministrator" requested priviledges. I have also tried setting the ClickOnce security settings to Full trust, which is incompatible with requireAdministrator, or so Visual Studio tells me.... Nothing seems to help with avoiding this exception.

I would just like to iterate over all of the keys. I do not wish to add/delete keys. If a user wishes to delete a key and does not have permission to do so, it would display an error message. I just want to be able to have unrestricted READ access. Is this possible?

FTR: I'm on Win7 x64 and using Vs2010u and project is written in C# on .net 4.0. If regedit is capable of reading all keys even if it doesn't let you edit some of them. It would seem appropriate that we too can make an app to do the same thing. Though I'm finding it very difficult, and there doesn't seem to be any real help on the www. Only link-link circles, yay.

[EDIT]

Here's the code that reads the keys:

    private void IterateSubKeys(RegistryKeyModel key) {

        var subKeys = key.Key.GetSubKeyNames();
        var values = key.Key.GetValueNames();

        foreach (var valuename in values) {
            try {
                var valueKind = key.Key.GetValueKind(valuename);
                var value = key.Key.GetValue(valuename);

                key.Values.Add(new RegistryValueModel(valuename, value, valueKind));
            }
            catch { }
        }

        foreach (var keyname in subKeys) {
            try {
                var subkey = key.Key.OpenSubKey(
                    keyname, 
                    RegistryKeyPermissionCheck.ReadSubTree, 
                    RegistryRights.ReadKey);

                key.SubKeys.Add(new RegistryKeyModel(subkey));
            }
            catch { Console.WriteLine("Error reading key: {0}", keyname); }
        }
    }

Upvotes: 0

Views: 1162

Answers (1)

Hans Passant
Hans Passant

Reputation: 942308

This is by design. There are lots of security related keys that can only accessible to the System account. You can't use that account. Regedit can't read these keys either, they are just not visible. Avoiding the expensive exception is going to require pinvoke.

Upvotes: 2

Related Questions