2

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)?

1 Answer 1

1

I'm sorry but AFAIK there's no way you can do that with built-in .NET registry functions; you will have to build your own text parser or use one that's already been made to get the keys inside your file.

See this and this saying the same thing; this project is a registry parser with about 40 stars on GitHub.

Sign up to request clarification or add additional context in comments.

2 Comments

Btw it's been almost 20 days since you asked this question; did you come up with something else?
I have unfortunately not found a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.