15

ASP.NET ではなく、通常の C# を使用しています。Chrome と Firefox のバージョンを入手できるかどうか疑問に思っていました。IEの場合、レジストリからバージョンを取得できることを知っています。私が知る限り、Chrome と Firefox はその情報をレジストリに保存しません。

前もって感謝します。

4

1 に答える 1

18

アプリケーションの完全なパスがわかっている場合は、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
于 2013-01-13T03:21:10.630 に答える