如何检测是否安装了Microsoft Edge?

6

我是一个Windows窗体应用程序(C#)的开发者,我需要检测用户的计算机上是否安装了“Microsoft Edge”浏览器。

目前,我正在使用以下注册表位置:

[HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages\Microsoft.MicrosoftEdge_20.10240.16384.0_neutral__8wekyb3d8bbwe]
"Path"="C:\\Windows\\SystemApps\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"

使用“Microsoft.MicrosoftEdge”后的 正则表达式。如果“路径”存在,则说明安装了Edge。

有更好的方法来检测Edge吗?如果我检测到我正在运行Windows 10,并且默认情况下Win10带有Edge,那么是否更好?如何最好地实现这一点?


2
是的,Windows 10自带Microsoft Edge浏览器,我认为您无法从中卸载Edge,并且您绝对无法在先前版本的Windows中安装它。 - sebagomez
2
我一直在寻找一种方法来做你想做的事情。我发现你的方法是迄今为止最好的。 如果未来的Windows版本放弃Edge,你的代码仍将有效。 基于操作系统版本推断功能的存在真的不比测试功能本身更好。 我只希望这个密钥是最好的;) 干杯。 - iannakin
我很高兴听到这个消息。 如果您找到更好的,请更新 :) - Aviram Fireberger
1
你实际上可以卸载Microsoft Edge。它像其他所有应用程序一样是一个包装应用程序。 - BeanFlicker
4个回答

3
如果您想要一个小程序来获取该版本号:
static void Main(string[] args)
    {
        string EdgeVersion = string.Empty;
        //open the registry and parse through the keys until you find Microsoft.MicrosoftEdge
        RegistryKey reg = Registry.ClassesRoot.OpenSubKey(@"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages");
        if (reg != null)
        {
            foreach (string subkey in reg.GetSubKeyNames())
            {
                if (subkey.StartsWith("Microsoft.MicrosoftEdge"))
                {
                    //RegEx: (Microsoft.MicrosoftEdge_)(\d +\.\d +\.\d +\.\d +)(_neutral__8wekyb3d8bbwe])
                    Match rxEdgeVersion = null;
                    rxEdgeVersion = Regex.Match(subkey, @"(Microsoft.MicrosoftEdge_)(?<version>\d+\.\d+\.\d+\.\d+)(_neutral__8wekyb3d8bbwe)");
                    //just after that value, you need to use RegEx to find the version number of the value in the registry
                    if ( rxEdgeVersion.Success )
                        EdgeVersion = rxEdgeVersion.Groups["version"].Value;
                }
            }
        }

        Console.WriteLine("Edge Version(empty means not found): {0}", EdgeVersion);
        Console.ReadLine();
    }

感谢您提供的注册表链接,以查找版本号。

直接复制这段代码对我来说可以很好地获取Edge版本。Microsoft Edge版本=41.16299.492.0 - Bill Tarbell
我刚在Windows 10上测试了一下。它返回了“Edge版本(空表示未找到):44.19041.423.0”。但是,当我启动Microsoft Edge(Chromium)并检查关于窗口时,它显示:“版本86.0.622.56(官方构建)(64位)”。所以我很困惑。 - Andrew Truckle

2

这里有一些有趣的参考资料,可以检测Windows版本。 - Vizor

0
关于其他答案的参考:我的Windows 10安装中没有这个键:Microsoft.MicrosoftEdge_20.10240.16384.0_neutral__8wekyb3d8bbwe 在:
[HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages\]

相反,它具有以下键:

Microsoft.MicrosoftEdge_38.14393.0.0_neutral__8wekyb3d8bbwe
Microsoft.MicrosoftEdge_40.15063.674.0_neutral__8wekyb3d8bbwe

以下代码可用于检测是否安装了Edge:
class Program
{
    static void Main(string[] args)
    {
        var edgeFound = false;
        using (var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages\"))
        {
            if (key != null)
            {
                foreach (var subkey in key.GetSubKeyNames())
                {
                    if (subkey.StartsWith("Microsoft.MicrosoftEdge_"))
                    {
                        edgeFound = true;
                        break;
                    }
                }
            }
        }
        Console.Write(edgeFound);
        Console.ReadLine();
    }
}

0

与2016年11月15日相关:

我发现唯一有效的方法是使用此注册表位置:

[HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages\Microsoft.MicrosoftEdge_20.10240.16384.0_neutral__8wekyb3d8bbwe]
"Path"="C:\\Windows\\SystemApps\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"

使用 "Microsoft.MicrosoftEdge" 后面的 regex

如果存在 "path",则说明 Edge 已安装。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接