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

时间:2015-11-08 13:18:49

标签: c# windows registry windows-10 microsoft-edge

我正在编写一个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"之后使用regex。如果"路径"然后我知道已经安装了边缘。

有没有更好的方法来检测边缘?如果我发现我在Windows 10上运行并且默认情况下Win10带有优势会更好吗?最好的方法是什么?

4 个答案:

答案 0 :(得分:1)

如果您使用的是Windows 10的桌面版或移动版,则Edge已预先安装且无法卸载。

要检测在Windows 10上运行是否使用System.Environment.OSVersion属性或Version Helper functions。 (另见https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx

如果要检测默认浏览器,您应该看到How to determine the Windows default browser (at the top of the start menu)

答案 1 :(得分:1)

如果您想让一个小程序获得该版本号:

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();
    }

感谢您找到版本号的注册表链接。

答案 2 :(得分: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

如果“路径”存在,那么我知道已经安装了边缘。

答案 3 :(得分: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();
    }
}