This is probably due to UAC (User Account Control). Extra security for Windows Vista and Windows 7.
You will need to request permissions for the registry.
EDIT : Your code now:
var keys = Registry.LocalMachine.OpenSubKey("SOFTWARE") .OpenSubKey("Microsoft") .OpenSubKey("Cryptography", RegistryKeyPermissionCheck.ReadSubTree) .GetValueNames();
Only asks for permission in the cryptography unit, maybe this causes a problem (at least I had it once), so the new code will be as follows:
var keys = Registry.LocalMachine.OpenSubKey("SOFTWARE", RegistryKeyPermissionCheck.ReadSubTree) .OpenSubKey("Microsoft", RegistryKeyPermissionCheck.ReadSubTree) .OpenSubKey("Cryptography", RegistryKeyPermissionCheck.ReadSubTree) .GetValueNames();
EDIT2:
I attached a debugger to it, according to this code:
var key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE", RegistryKeyPermissionCheck.ReadSubTree); var key2 = key1.OpenSubKey("Microsoft", RegistryKeyPermissionCheck.ReadSubTree); var key3 = key2.OpenSubKey("Cryptography", RegistryKeyPermissionCheck.ReadSubTree); var key4 = key3.GetValueNames();
It turns out you can read this particular value, at least my guess, because all the data is correct until I open key3, there the ValueCount is zero, not the expected one.
I think this is a special meaning that is protected.
Aidiakapi Mar 10 '11 at 16:44 2011-03-10 16:44
source share