1

I am trying to create a key in the uninstall entry in the registry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall but when I run the code it instead creates it in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wow6432Node\Microsoft\Windows\CurrentVersion, I don't understand where it could be getting this path from.

Below is the code that I am using

private void addToRegistry(string installPath)
{
    using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
    {
        if (parent == null)
        {
            MessageBox.Show("Failed to open registry key. Installation cannot continue", "Registry Error", 
                MessageBoxButton.OK, MessageBoxImage.Error);
        }
        try
        {
            RegistryKey key = null;
            string appParent = "Boardies Email Server";
            parent.CreateSubKey(appParent);
            key = parent.OpenSubKey(appParent);
            //key = parent.OpenSubKey(appParent, true) ??
            //    parent.CreateSubKey(appParent);
            if (key == null)
            {
                MessageBox.Show("Failed to add registry entry. Error: nInstallation Aborted", "Registry Error", 
                    MessageBoxButton.OK, MessageBoxImage.Error);
                throw new Exception();
            }

            Assembly asm = GetType().Assembly;
            Version version = asm.GetName().Version;
            string exe = string.Format("{0}\\EmailServer.exe", installPath);

        }
        catch (Exception ex)
        {
            MessageBox.Show(string.Format("Failed to install, unable to insert into registry: {0}\n\nInstallation Aborted", ex.Message),
                "Registry Error", MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }

Thanks for any help you can provide.

Boardy
  • 35,417
  • 104
  • 256
  • 447

3 Answers3

1

Probably, your application is 32 bits, in Windows x64 the Register is virtualized so 32 bits and 64 bits apps can coexist and use the same register keys; so your app sees that is writing in this path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

But is really writing on this path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wow6432Node\Microsoft\Windows\CurrentVersion

So in theory if you require such key from another 32 bits app, there should not be problems as it will also see this path as.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Rafael
  • 2,827
  • 1
  • 16
  • 17
  • Hmmm, this doesn't appear to be the case as I am trying to add the program into the Uninstall programs menu doesn't show up in there when its in the Wow6432Node menu – Boardy Aug 06 '12 at 19:36
0

It is a Registry Redirector.

Try using the RegistryView Enumeration for RegistryKey.OpenBaseKey Method, see the RegistryView.Registry64 enum member.

By the way, you can allow your program to run as a 64-bit process so there would be no redirection: Project => Properties => Build tab: change Platform target to AnyCPU.

0

That's because you have to change the value at the correct top level. You can identify the correct location with autoruns.exe. It will point you to the right location!

(see example below in which I disabled a file system check when Windows boots up)

enter image description here

This tool not only locates all startup registry keys, but all other services as well, including 3rd party installs!

Joe R.
  • 2,032
  • 4
  • 36
  • 72