检查应用程序安装在注册表中 [英] Check if application is installed in registry
问题描述
现在我用这个来列出在注册表中为32位和放大器中列出的所有应用程序; 64。
我已经看到了如何检查其他例子如果应用程序没有任何运气安装。
Right now I use this to list all the applications listed in the registry for 32bit & 64. I have seen the other examples of how to check if an application is installed without any luck.
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue("DisplayName"));
}
}
registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue("DisplayName"));
}
}
所以这个片段中列出了这一切在控制台窗口和我所试图做的是
随便找一个节目标题显示出来的名称列表,看它是否安装。
So this snippet lists it all in the console window and what I am trying to do is just find one program title out of the list of display names to see if it's installed.
我试过的最后一件事是
if (subkey.Name.Contains("OpenSSL"))
Console.Writeline("OpenSSL Found");
else
Console.Writeline("OpenSSL Not Found");
什么我想回来有误或假阳性。是否有任何人能告诉我怎么随便抓一个标题淘汰之列?
Anything I tried came back either false or a false positive. Is there anyone that can show me how to just grab a title out of the list?
请不要发布了著名的私有静态无效IsApplicationInstalled(p_name)函数。它不工作,为我所有。
Please don't post up the well-known private static void IsApplicationInstalled(p_name) function. It does not work for me at all.
推荐答案
搜索和故障排除之后,我得到它的工作是这样的:
After searching and troubleshooting, I got it to work this way:
public static bool checkInstalled (string c_name)
{
string displayName;
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(c_name))
{
return true;
}
}
key.Close();
}
registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(c_name))
{
return true;
}
}
key.Close();
}
return false;
}
和我简单地使用叫它
if(checkInstalled("Application Name"))
这篇关于检查应用程序安装在注册表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!