我正在尝试在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
中的注册表中的卸载条目中创建一个密钥,但是当我运行代码时,它会在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wow6432Node\Microsoft\Windows\CurrentVersion
中创建它,我不明白它可能在哪里获得这条路来自。
以下是我正在使用的代码
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);
}
}
感谢您提供的任何帮助。
答案 0 :(得分:1)
可能你的应用程序是32位,在Windows x64中,寄存器是虚拟化的,因此32位和64位应用程序可以共存并使用相同的寄存器键;所以你的应用程序看到正在写这条道路:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
但实际上是在写这条道路:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wow6432Node\Microsoft\Windows\CurrentVersion
所以理论上如果你需要来自另一个32位应用程序的密钥,那么应该没有问题,因为它也会看到这条路径。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
答案 1 :(得分:0)
尝试使用RegistryView Enumeration RegistryKey.OpenBaseKey Method,请参阅RegistryView.Registry64枚举成员。
顺便说一句,您可以允许程序作为64位进程运行,因此不会有重定向:Project =>属性=>构建选项卡:将平台目标更改为 AnyCPU 。
答案 2 :(得分:0)
那是因为您必须在正确的顶级更改值。您可以使用autoruns.exe确定正确的位置。它会指向正确的位置!
(参见下面的例子,我在Windows启动时禁用了文件系统检查)
此工具不仅可以找到所有启动注册表项,还可以查找所有其他服务,包括第三方安装!