2012-08-06 13 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

該工具不僅查找所有啓動的註冊表鍵,但所有其他服務,以及包括第三方安裝!