In C# .NET 2.0 or greater, how to get list of all installed applications on Vista PC
Using C# .NET 2.0 or greater and Visual Studio 2008, how would one generate a list of all installed applications on a Windows Vista PC?
My motivation is to get a text file of all my installed applications that I can save and keep around so that when I rebuild my machine 开发者_如何学PythonI have a list of all of my old applications.
The second part of this question is kind of SuperUser.com thing, but hopefully the first part counts as "programming".
Thanks
You could look into referencing the SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall registry key. Check out these links:
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 follwing will get you the installed apps for all users. Do the same for Registry.CurrentUser as well:
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);
}
DISCLAIMER: There is no null value/error checking in my sample!
See the source code of this library
foreach(var info in BlackFox.Win32.UninstallInformations.Informations.GetInformations())
{
Console.WriteLine(info.ToString());
}
One must also account for different levels of installedness.
- An app may have had things done to it (deleted, etc.) since it was installed.
- Some apps don't 'install', but rather run as naked binaries.
精彩评论