使用C#.NET 2.0或更高版本以及Visual Studio 2008,如何生成Windows Vista PC上所有已安裝應用程序的列表?在C#.NET 2.0或更高版本中,如何獲取Vista上所有已安裝應用程序的列表PC
我的動機是獲取我可以保存和保留的所有已安裝應用程序的文本文件,以便在重建我的機器時,我有一個所有舊應用程序的列表。
這個問題的第二部分是一種SuperUser.com的事情,但希望第一部分被視爲「編程」。
感謝
使用C#.NET 2.0或更高版本以及Visual Studio 2008,如何生成Windows Vista PC上所有已安裝應用程序的列表?在C#.NET 2.0或更高版本中,如何獲取Vista上所有已安裝應用程序的列表PC
我的動機是獲取我可以保存和保留的所有已安裝應用程序的文本文件,以便在重建我的機器時,我有一個所有舊應用程序的列表。
這個問題的第二部分是一種SuperUser.com的事情,但希望第一部分被視爲「編程」。
感謝
你可以看看引用SOFTWARE \微軟\的Windows \ CurrentVersion \ Uninstall註冊表鍵。看看這些鏈接:
http://www.onedotnetway.com/get-a-list-of-installed-applications-using-linq-and-c/ http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/ac23690a-f5f8-46fc-9047-c369f4370fac
見the source code of this library
foreach(var info in BlackFox.Win32.UninstallInformations.Informations.GetInformations())
{
Console.WriteLine(info.ToString());
}
還必須考慮不同層次installedness的。
該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);
}
免責聲明:不存在空值/錯誤我的樣品中檢查!
當然,這隻會返回註冊表中列出的應用程序列表。通過XCOPY部署部署的應用程序不會顯示。 – pmarflee 2009-10-21 20:42:58
是的,可能不是Adam的所有應用程序都會出現在註冊表中,因爲它們可能是複製到磁盤上而不是安裝的應用程序。 – 2009-10-21 20:48:27
謝謝。 StackOverflow規則! – 2009-10-21 20:51:38