gpt4 book ai didi

c# - 如何在 Windows 上使用 C# 获取 chrome.exe 的路径?

转载 作者:行者123 更新时间:2023-12-04 14:34:35 24 4
gpt4 key购买 nike

我想从我的自动化测试框架启动 chrome,以便我可以测试我的服务器端 ASP.NET 代码。确定 chrome.exe 在我的计算机上的位置的最佳方法是什么?

最佳答案

当 Chrome 安装在计算机上时,它会安装 ChromeHTML网址协议(protocol)。您可以使用它来获取 Chrome.exe 的路径。

一些示例代码可能会有所帮助。以下代码返回一个如下所示的字符串:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"

获取该示例代码:
var path = Microsoft.Win32.Registry.GetValue(
@"HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command", null, null) as string;
if (path != null)
{
var split = path.Split('\"');
path = split.Length >= 2 ? split[1] : null;
}

如果代码段末尾的 path 为空,则可以假设未安装 Chrome。

关于c# - 如何在 Windows 上使用 C# 获取 chrome.exe 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45384893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com