【发布时间】:2015-05-19 21:45:01
【问题描述】:
我正在开发一个小工具,该工具实质上是在主机上查找多个已安装的软件。我发现了一段代码,它是一个更好的程序员用 C# 编写的,但是,我想知道两件事。 1.我用注册表标题替换什么来搜索已安装的软件?其次,我希望信息在找到的软件名称的文本框中显示。下面是代码。
public static bool IsApplictionInstalled(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;
}
【问题讨论】:
-
+1 因为我正在反对匿名不明原因的反对选民。对我来说,这似乎是一个完全合理的问题。
-
@Tim Long,哈哈,我很欣赏那个哥们
标签: c# textbox return-value boolean-logic registrykey