Andrew Raleigh
Andrew Raleigh

Reputation: 29

Modifying 64-bit registries using 32-bit application or vice versa

I've seen answers for this in C#, but the C++ solutions I've used haven't been working for me. I can make the application 64-bit, but then I lose out on modifying the 32-bit registries, so I'd like to modify both registries in a single application.

Right now I've found 32-bit on 64 works more, so I'm going that route - but if it's easier to do 64-bit accessing 32-bit let me know.

I use the following to init: RegistryKey^ key = Registry::LocalMachine;

Then the following to delete a registry value:

        if (key->OpenSubKey(PATH)) {
            key->DeleteSubKeyTree(PATH);
        }

PATH is something like SOFTWARE\\WOW6432Node\\Apple Computer, Inc.\\QuickTime

Now, depending on if the c++ architecture is 32 or 64-bit, I can delete one or the other. Deleting both is the hassle.

Is there something like this for 64-bit:

RegistryKey^ wygRegKey = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");

If anything, I can send cmd commands to delete the registry and then check if it exists for logs, but I'd prefer not to risk missing errors.

Upvotes: 0

Views: 422

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595827

You need to use RegistryKey.OpenBaseKey() to create a RegistryKey object for the desired view (32bit or 64bit) of the Registry.

RegistryKey ^key = RegistryKey::OpenBaseKey(RegistryHive::LocalMachine, RegistryView::Registry32);
// the next call maps to "SOFTWARE\\WOW6432Node\\Apple Computer" on a 64bit system...
if (key->OpenSubKey("SOFTWARE\\Apple Computer, Inc."))
{
    key->DeleteSubKeyTree("QuickTime");
    key->Close();
}
string path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
RegistryKey^ key;

key = RegistryKey::OpenBaseKey(RegistryHive::LocalMachine, RegistryView::Registry32);
key->DeleteSubKeyTree(path);

key = RegistryKey::OpenBaseKey(RegistryHive::LocalMachine, RegistryView::Registry64);
key->DeleteSubKeyTree(path);

Upvotes: 1

Related Questions