I'm writing a utility that needs to create a list of all registry values in HKCR. I am doing this using a recursive function:
var list = new Dictionary<string, string>();
Read(Registry.ClassesRoot, list);
static void Read(RegistryKey root, IDictionary<string, string> values)
{
foreach (var child in root.GetSubKeyNames())
{
using (var childKey = root.OpenSubKey(child))
{
Read(childKey, values);
}
}
foreach (var value in root.GetValueNames())
{
values.Add(string.Format("{0}\\{1}", root, value), (root.GetValue(value) ?? "").ToString());
}
}
This works fine, but it takes a good chunk of time (20 seconds on my PC). Is there a faster way to do this, or is this as good as it gets?
In the search box on the taskbar, type regedit, then select Registry Editor (Desktop app) from the results. Right-click Start , then select Run. Type regedit in the Open: box, and then select OK.
One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .
Because the Windows registry is a hierarchy, the way regedit is laid out makes typical searches inefficient and slow. Typically, when performing a search in regedit, you highlight the first line ('Computer') and then perform the search.
Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion. This command gets the value name and data of the ProgramFilesDir registry entry in the CurrentVersion registry subkey. The command uses the Path parameter to specify the subkey and the Name parameter to specify the value name of the entry.
There's a lot of information in the registry and as others have noted here - speed can be an issue. If you want a list of registry settings to display in a tree-like view for the user to browse through, a better solution might be to scan the top level entries first, then as the user navigates through the tree, so you scan for those child values/settings as the tree node is opening.
I suspect this is how Microsoft's own regedit works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With