检测已安装的所以的Process.Start浏览器("镀铬")将不会错误镀铬、浏览器、错误、Process

2023-09-03 21:07:07 作者:↘2B青年,

我试图让用户选择我的应用程序使用的URL启动浏览器。目前,它使用默认的浏览器,但有些人要指定一个不同的浏览器。

I'm trying to let the user choose the browser my application uses to launch urls. Currently it uses the default browser, but some people want to specify a different browser.

我想只显示安装的浏览器列表中,而且我发动他们是这样的:

I'd like to show only installed browsers in the list, and I'm launching them like this:

的Process.Start(铬,网址);

Process.Start("chrome", url);

的问题是,如果未安装浏览器(和路径),它会失败。

The problem is, if Chrome isn't installed (and in the path), it'll fail.

如何查询此调用是否会失败,而不调用它(这样我就可以pre-筛选我的名单,并删除铬如果它没有去上班)?

How can I check whether this call will fail, without calling it (so I can pre-filter my list, and remove chrome if it's not going to work)?

推荐答案

在Windows中的所有已安装的应用程序已经在 HKEY_LOCAL_MACHINE \ SOFTWARE \微软\的Windows一键\ CURRENTVERSION \应用程序路径注册表项。一个解决办法是遍历这个关键中的所有条目,看看他们是否符合您的支持的浏览器的名称。

In Windows all of the installed applications have a key in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths registry key. One solution would be to iterate over all the entries in this key and see if they match the names of your supported browsers.

一旦你为每个浏览器的注册表项,就可以得到每个键的路径值,看看是否可执行文件存在于指定的路径

Once you've got the registry keys for each browser, you can then get the Path value of each key, and see if the executable file exists in the specified path.

有一点需要注意的是,在64位版本的Windows,32位应用程序列在 HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \微软\的Windows \ CurrentVersion \应用程序路径

One thing to note is that on 64-bit versions of Windows, 32-bit apps are listed in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths.