2009-10-21 20 views
2

使用C#.NET 2.0或更高版本以及Visual Studio 2008,如何生成Windows Vista PC上所有已安裝應用程序的列表?在C#.NET 2.0或更高版本中,如何獲取Vista上所有已安裝應用程序的列表PC

我的動機是獲取我可以保存和保留的所有已安裝應用程序的文本文件,以便在重建我的機器時,我有一個所有舊應用程序的列表。

這個問題的第二部分是一種SuperUser.com的事情,但希望第一部分被視爲「編程」。

感謝

回答

5
+0

當然,這隻會返回註冊表中列出的應用程序列表。通過XCOPY部署部署的應用程序不會顯示。 – pmarflee 2009-10-21 20:42:58

+0

是的,可能不是Adam的所有應用程序都會出現在註冊表中,因爲它們可能是複製到磁盤上而不是安裝的應用程序。 – 2009-10-21 20:48:27

+0

謝謝。 StackOverflow規則! – 2009-10-21 20:51:38

1

the source code of this library

foreach(var info in BlackFox.Win32.UninstallInformations.Informations.GetInformations()) 
{ 
    Console.WriteLine(info.ToString()); 
} 
0

還必須考慮不同層次installedness的。

  • 應用程序自安裝以來可能已對其執行了任務(刪除等)。
  • 有些應用程序不能'安裝',而是作爲裸二進制文件運行。
2

該follwing將爲您帶來所有用戶安裝的應用程序。用同樣的方法 Registry.CurrentUser還有:

RegistryKey uninstall = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); 
    List<string> applicationList = new List<string>(); 
    foreach (string subKeyName in uninstall.GetSubKeyNames()) 
    { 
     RegistryKey subKey = uninstall.OpenSubKey(subKeyName); 
     string applicationName = subKey.GetValue("DisplayName", String.Empty).ToString(); 
     if (!String.IsNullOrEmpty(applicationName)) 
     { 
      applicationList.Add(applicationName); 
     } 
     subKey.Close(); 
    } 

    uninstall.Close(); 

    applicationList.Sort(); 

    foreach (string name in applicationList) 
    { 
     Console.WriteLine(name);  
    } 

免責聲明:不存在空值/錯誤我的樣品中檢查!

相關問題