【发布时间】:2012-12-27 06:54:16
【问题描述】:
我只是使用常规的 C# 而不是 ASP.NET。我想知道我是否可以获得 Chrome 和 Firefox 的版本。我知道对于 IE,您可以通过注册表获取版本。据我所知,Chrome 和 Firefox 不会将该信息存储在注册表中。
提前致谢。
【问题讨论】:
标签: c# .net google-chrome firefox registry
我只是使用常规的 C# 而不是 ASP.NET。我想知道我是否可以获得 Chrome 和 Firefox 的版本。我知道对于 IE,您可以通过注册表获取版本。据我所知,Chrome 和 Firefox 不会将该信息存储在注册表中。
提前致谢。
【问题讨论】:
标签: c# .net google-chrome firefox registry
如果您知道应用程序的完整路径,那么您可以使用System.Diagnostics.FileVersionInfo 类来获取版本号。
这是一个简单的控制台应用程序,它从注册表中读取 Chrome 和 Firefox 的安装路径,并输出它们的版本号:
using System;
using System.Diagnostics;
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
object path;
path = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "", null);
if (path != null)
Console.WriteLine("Chrome: " + FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion);
path = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe", "", null);
if (path != null)
Console.WriteLine("Firefox: " + FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion);
}
}
示例输出:
Chrome: 24.0.1312.52
Firefox: 16.0.2
【讨论】: