2012-08-06 15 views
1

我试图创建在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

这是一个32位应用或64位的一个? – Rafael 2012-08-06 18:52:57

+0

可能的重复:http://stackoverflow.com/questions/7311146/write-the-registry-value-without-redirect-in-wow6432node http://stackoverflow.com/questions/2039186/c-sharp-reading-the -registry-and-wow6432node-key – 2012-08-06 19:00:05

回答

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 
+0

嗯,这似乎并不是这种情况,因为我试图将该程序添加到Uninstall程序菜单中,但在Wow6432Node菜单中没有显示 – Boardy 2012-08-06 19:36:01

0

这是因为您必须在正确的顶层更改值。您可以使用autoruns.exe来识别正确的位置。它会将您指向正确的位置!

(见下文中,我禁用的文件系统检查例如,当Windows启动)

enter image description here

该工具不仅查找所有启动的注册表键,但所有其他服务,以及包括第三方安装!