Riz*_*ski 11 .net c# registry firefox google-chrome
我只是使用常规的C#而不是ASP.NET.我想知道我是否可以获得Chrome和Firefox的版本.我知道IE可以通过注册表获得版本.据我所知,Chrome和Firefox不会将这些信息存储在注册表中.
提前致谢.
Mic*_*Liu 11
如果您知道应用程序的完整路径,则可以使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
样本输出:
Chrome: 24.0.1312.52
Firefox: 16.0.2
Run Code Online (Sandbox Code Playgroud)