我如何使用C#在Windows上获取chrome.exe的路径? [英] How do I use C# to get the path to chrome.exe on Windows?

查看:563
本文介绍了我如何使用C#在Windows上获取chrome.exe的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当Chrome安装在计算机,它会安装 ChromeHTML URL协议。您可以使用它来到Chrome.exe的路径。

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

 C:\程序文件(x86)\Google\ Chrome \Application\chrome.exe - %1

  var path = Microsoft.Win32.Registry.GetValue(
@HKEY_CLASSES_ROOT\ChromeHTML\shell\\ \\ open \\ command,null,null)作为字符串;
if(path!= null)
{
var split = path.Split('\');
path = split.Length> = 2?split [ 1]:null;
}

如果代码片段末尾的路径为null ,那么你可以假设没有安装Chrome。


I want to launch chrome from my automated test framework so that I can test my server-side ASP.NET code. What's the best way to determine the location of where chrome.exe is located on my computer?

解决方案

When Chrome is installed on a computer, it installs the ChromeHTML URL protocol. You could use that to get to the path for Chrome.exe.

Some example code may help. The following code returns a string that looks like this:

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

Example code to get that:

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

if path is null at the end of the code snippet, then you can assume Chrome isn't installed.

这篇关于我如何使用C#在Windows上获取chrome.exe的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆