我有以下代码: 这些值在调试器中显示如下: FF86_version“31.0.1” FF86_name“Firefox” displayFF86version“null” displayFF86name“null”
public static bool checkFF86version(string FF86_name, string FF86_version)
{
RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
//.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
string displayFF86version;
string displayFF86name;
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayFF86name = subkey.GetValue("DisplayName") as string;
if (displayFF86name != null && displayFF86name.Contains(FF86_name))
{
displayFF86version = subkey.GetValue("DisplayVersion") as string;
if (displayFF86version.Equals(FF86_version))
{
var version = displayFF86version; //Comes from the Registry
var parsedversion = Version.Parse(version);
var minimumversion = new Version(FF86_version); //Static Version Check
if (parsedversion >= minimumversion)
return true;
}
}
return false;
}
}
return false;
}
我正在尝试查看是否安装了“Firefox”。如果检测到,则比较DisplayVersion以查看它是否>或者<标识的版本显示如下:
if (checkFF86version("Firefox", "31.0.1"))
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox is Installed and is the latest version" });
else
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox needs updated" });
我已经解决了这个问题,我想我会为可能有这个问题的其他人发布解决方案。似乎答案很难找到。这可以为您节省一些时间。特别感谢(CodeProject)上的“CodeK”,以获得有关此解决方案的帮助。如果没有他,我就无法完成它。
public void GetNameAndVersion()
{
Microsoft.Win32.RegistryKey iRegKey = null;
Microsoft.Win32.RegistryKey iSubKey = null;
string eValue = null;
string eVersion = null;
string regpath = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
iRegKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regpath);
string[] subkeys = iRegKey.GetSubKeyNames();
bool includes = false;
foreach (string subk in subkeys)
{
iSubKey = iRegKey.OpenSubKey(subk);
eValue = Convert.ToString(iSubKey.GetValue("DisplayName", ""));
eVersion = Convert.ToString(iSubKey.GetValue("DisplayVersion", ""));
if (eValue != null && eValue.Contains("Firefox"))
{
var version = eVersion;
var parsedversion = Version.Parse(version);
var minimumversion = new Version("35.0.1");
if (parsedversion >= minimumversion)
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox is the latest version or newer" });
else if (parsedversion < minimumversion)
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox needs reinstalled" });
else
includes = false;
}
}
}
}
}
答案 0 :(得分:0)
我已经解决了这个问题,我想我会为可能有这个问题的其他人发布解决方案。似乎答案很难找到。这可以为您节省一些时间。特别感谢&#34; CodeK&#34; on(CodeProject)获取有关此解决方案的帮助。如果没有他,我就无法完成它。
public void GetNameAndVersion()
{
Microsoft.Win32.RegistryKey iRegKey = null;
Microsoft.Win32.RegistryKey iSubKey = null;
string eValue = null;
string eVersion = null;
string regpath = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
iRegKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regpath);
string[] subkeys = iRegKey.GetSubKeyNames();
bool includes = false;
foreach (string subk in subkeys)
{
iSubKey = iRegKey.OpenSubKey(subk);
eValue = Convert.ToString(iSubKey.GetValue("DisplayName", ""));
eVersion = Convert.ToString(iSubKey.GetValue("DisplayVersion", ""));
if (eValue != null && eValue.Contains("Firefox"))
{
var version = eVersion;
var parsedversion = Version.Parse(version);
var minimumversion = new Version("35.0.1");
if (parsedversion >= minimumversion)
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox is the latest version or newer" });
else if (parsedversion < minimumversion)
listView1.Items.Add(new ListViewItem { ImageIndex = 0, Text = "Firefox needs reinstalled" });
else
includes = false;
}
}
}
}
}