如何检测是否安装了 Microsoft Edge?
How can I detect if Microsoft Edge is installed?
我正在编写一个 windows 表单应用程序 (c#),我需要检测用户是否在 his/her 机器上安装了 "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
。如果 "path" 存在,那么我知道 edge 已安装。
有没有更好的检测边缘的方法?如果我在 Windows 10 上检测到我是 运行 并且默认情况下 Win10 带有 edge 会更好吗?最好的方法是什么?
如果您使用的是 Windows 10 的桌面版或移动版,则 Edge 已预装且无法卸载。
要检测 Windows 10 上是否有 运行,请使用 System.Environment.OSVersion property or the Version Helper functions. (See also 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)
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 已安装。
参考其他答案:我安装的Windows10没有这个key: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();
}
}
如果你想让一个小程序获得那个版本号:
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();
}
感谢注册表 link 查找版本号。
我正在编写一个 windows 表单应用程序 (c#),我需要检测用户是否在 his/her 机器上安装了 "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
。如果 "path" 存在,那么我知道 edge 已安装。
有没有更好的检测边缘的方法?如果我在 Windows 10 上检测到我是 运行 并且默认情况下 Win10 带有 edge 会更好吗?最好的方法是什么?
如果您使用的是 Windows 10 的桌面版或移动版,则 Edge 已预装且无法卸载。
要检测 Windows 10 上是否有 运行,请使用 System.Environment.OSVersion property or the Version Helper functions. (See also 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)
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 已安装。
参考其他答案:我安装的Windows10没有这个key: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();
}
}
如果你想让一个小程序获得那个版本号:
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();
}
感谢注册表 link 查找版本号。