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.