我正在编写一个 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
。如果“路径”存在,那么我知道 edge 已安装。
是否有更好的检测边缘的方法?如果我检测到我在 Windows 10 上运行并且默认情况下 Win10 附带 edge 会更好吗?最好的方法是什么?
最佳答案
如果你想让一个小程序获得那个版本号:
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();
}
感谢您提供用于查找版本号的注册表链接。
关于c# - 如何检测是否安装了 Microsoft Edge?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33594401/