windows 获取系统中所有应用程序
前言:
记录下。
重点
RegistryView.Registry64 与 RegistryView.Registry32 。有些程序在 Registry64 中,有些程序在 Registry32 中。
代码
查看代码
var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = localMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
var displayName = sk.GetValue("DisplayName") ?? "";
if (string.IsNullOrWhiteSpace(displayName.ToString()))
{
continue;
}
var size = sk.GetValue("EstimatedSize") ?? "";
var displayVersion = sk.GetValue("DisplayVersion") ?? "";
var installDate = sk.GetValue("InstallDate") ?? "";
var publisher = sk.GetValue("Publisher") ?? "";
var installLocation = sk.GetValue("InstallLocation") ?? "";
var version = sk.GetValue("Version") ?? "";
var versionMinor = sk.GetValue("VersionMinor") ?? "";
var versionMajor = sk.GetValue("VersionMajor") ?? "";
var uninstallString = sk.GetValue("UninstallString") ?? "";
var helpLink = sk.GetValue("HelpLink") ?? "";
var DisplayIcon = sk.GetValue("DisplayIcon") ?? "";
var HelpTelephone = sk.GetValue("HelpTelephone") ?? "";
var InstallSource = sk.GetValue("InstallSource") ?? "";
var URLInfoAbout = sk.GetValue("URLInfoAbout") ?? "";
var URLUpdateInfo = sk.GetValue("URLUpdateInfo") ?? "";
var AuthorizedCDFPrefix = sk.GetValue("AuthorizedCDFPrefix") ?? "";
var Contact = sk.GetValue("Contact") ?? "";
var Comments = sk.GetValue("Comments") ?? "";
var Language = sk.GetValue("Language") ?? "";
var ModifyPath = sk.GetValue("ModifyPath") ?? "";
var Readme = sk.GetValue("Readme") ?? "";
var SettingsIdentifier = sk.GetValue("SettingsIdentifier") ?? "";
ListViewItem item = new ListViewItem(new string[]
{
displayName.ToString(),
size.ToString(),
displayVersion.ToString(),
installDate.ToString(),
publisher.ToString(),
installLocation.ToString(),
versionMajor.ToString(),
version.ToString(),
versionMinor.ToString(),
uninstallString.ToString(),
helpLink.ToString(),
DisplayIcon.ToString(),
HelpTelephone.ToString(),
InstallSource.ToString(),
URLInfoAbout.ToString(),
URLUpdateInfo.ToString(),
AuthorizedCDFPrefix.ToString(),
Contact.ToString(),
Comments.ToString(),
Language.ToString(),
ModifyPath.ToString(),
Readme.ToString(),
SettingsIdentifier.ToString(),
});
lstDisplayHardware.Items.Add(item);
}
catch (Exception ex)
{
}
}
}
}
我的源代码仓库如果对您有帮助的话,star一下吧
本文作者:youliCC