From different machines, I have exported different branches of the registry. (The whole registry was too large to take in its entirety.)
I have saved these registries on .reg files on my own machine, and so far have only examined them as plaintext. I don't want to open them with Regedit because I don't want the keys to merge with my machine's registry.
In my C# application, in an attempt to determine if a piece of software is installed, I have been examining my machine's existing registry.
string REGISTRY_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string REGISTRY_NAME = "Name of Software";
bool is64bit = true;
RegistryView registryView = is64Bit ? RegistryView.Registry64 : RegistryView.Registry32;
RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(REGISTRY_KEY);
if (registryKey != null)
{
using (registryKey)
{
foreach (string subkeyName in registryKey.GetSubKeyNames())
{
using (RegistryKey subkey = registryKey.OpenSubKey(subkeyName))
{
string displayName = (string)subkey.GetValue("DisplayName");
if (displayName != null && displayName.Contains(REGISTRY_NAME))
{
Console.WriteLine( "Found the program" );
}
}
}
}
}
This searches within the 64-bit view of my machine's HKLM.
However, now I want to run this same code, but instead of using my machine's registry file, I want to use one of the exported .reg files I have.
The branch I exported from is the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion branch.
How do I use the RegistryKey tools with C# to open a registry file saved on my machine (but is not the actual registry for my own machine)?