[英]Get installed software list using C#
I try to get a list of installed application keys:我尝试获取已安装应用程序密钥的列表:
RegistryKey RegKeyUninstallList = Registry.LocalMachine;
string strUninstallList = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string[] test = RegKeyUninstallList.OpenSubKey(strUninstallList).GetSubKeyNames();
I get only the Keys from:我只从以下位置获得钥匙:
HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall
HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall
But I need also the Keys from:但我还需要来自:
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
My program should be able to run on a 64Bit
and on a 32Bit
machine.我的程序应该能够在
64Bit
和32Bit
机器上运行。
edit: Ok I have tried Check if application is installed in registry and the solution from tHiNk_OuT_oF_bOx.编辑:好的,我已经尝试检查应用程序是否安装在注册表中,以及来自 tHiNk_OuT_oF_bOx 的解决方案。
But nothing has solved the Problem!但没有什么能解决问题!
The problem is i get exactly the same list for test and test2:问题是我得到了完全相同的 test 和 test2 列表:
RegistryKey RegKeyUninstallList = Registry.LocalMachine;
string strUninstallList = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string strUninstallList2 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
string[] test = RegKeyUninstallList.OpenSubKey(strUninstallList).GetSubKeyNames();
string[] test2 = RegKeyUninstallList.OpenSubKey(strUninstallList2).GetSubKeyNames();
Source from : http://social.msdn.microsoft.com/Forums/en-US/94c2f14d-c45e-4b55-9ba0-eb091bac1035/c-get-installed-programs来源: http : //social.msdn.microsoft.com/Forums/en-US/94c2f14d-c45e-4b55-9ba0-eb091bac1035/c-get-installed-programs
The solution is to search for 3 places in registry:解决方案是在注册表中搜索 3 个位置:
the code below suits you needs.下面的代码适合您的需要。
public static bool IsApplicationInstalled(string p_name)
{
string displayName;
RegistryKey key;
// search in: CurrentUser
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
// search in: LocalMachine_32
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
// search in: LocalMachine_64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
// NOT FOUND
return false;
}
It seems you now have to use OpenBaseKey, there is the code im using:看来您现在必须使用 OpenBaseKey,我正在使用以下代码:
List<string> gInstalledSoftware
void GetInstalledSoftwareList()
{
string displayName;
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false))
{
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(displayName))
continue;
gInstalledSoftware.Add(displayName.ToLower());
}
}
//using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false))
using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
var key = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(displayName))
continue;
gInstalledSoftware.Add(displayName.ToLower());
}
}
using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
var key = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(displayName))
continue;
gInstalledSoftware.Add(displayName.ToLower());
}
}
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",false))
{
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(displayName))
continue;
gInstalledSoftware.Add(displayName.ToLower());
}
}
}
All answers fail to retrieve every installed application on Windows 10. The codes above only display most used installed apps NOT all installed apps .所有答案都无法在 Windows 10 上检索每个已安装的应用程序。上面的代码仅显示最常用的已安装应用程序,而不是所有已安装的应用程序。 So I found this solution:
所以我找到了这个解决方案:
string appPATH = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(appPATH))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
//Get App Name
var displayName = sk.GetValue("DisplayName");
//Get App Size
var size = sk.GetValue("EstimatedSize");
string item;
if (displayName != null)
{
if (size != null)
item = displayName.ToString();
else
{
item = displayName.ToString();
if (item.Contains(""))
MessageBox.Show(displayName.ToString());
}
}
}
catch (Exception ex)
{ }
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Microsoft.Win32;
public void GetInstalledApps()
{
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
listBox1.Items.Add(sk.GetValue("DisplayName"));
}
catch (Exception ex)
{ }
}
}
label1.Text = listBox1.Items.Count.ToString();
}
}
I used this code, its a bit more abstract and it checks for 32/64 bit OS.我使用了这段代码,它更抽象一点,它检查 32/64 位操作系统。 It also uses C#V8 features for simplicity.
为简单起见,它还使用 C#V8 功能。
public static bool CheckAppInstallation(string programName)
{
bool result = false;
string uninstallKey1 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string uninstallKey2 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
result |= CheckInAddress(uninstallKey1, RegistryHive.LocalMachine, programName);
result |= CheckInAddress(uninstallKey1, RegistryHive.CurrentUser, programName);
result |= CheckInAddress(uninstallKey2, RegistryHive.LocalMachine, programName);
return result;
static bool CheckInAddress(string address, RegistryHive hive, string programName)
{
var view = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
using var localKey = RegistryKey.OpenBaseKey(hive, view).OpenSubKey(address);
foreach (var subKey in localKey.GetSubKeyNames().Select(keyName => localKey.OpenSubKey(keyName)))
if (subKey.GetValue("DisplayName") is string displayName && displayName.Contains(programName))
return true;
return false;
}
}
Can you try to add the reference "System.Management" in your project and after use this code:您可以尝试在您的项目中添加引用“System.Management”并在使用此代码后:
I think more easy我觉得更容易
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach (ManagementObject mo in mos.Get())
{
Console.WriteLine(mo["Name"]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.