[英]DefaultBrowser from Registry doesn't work
I'm trying to open a url in the default browser. 我正在尝试在默认浏览器中打开一个URL。 Obviously I thought that Shell Exec will open it in the default browser but it doesn't. 显然,我认为Shell Exec将在默认浏览器中将其打开,但不会。
Then I tried explicit: 然后我尝试显式:
Process.Start(GetDefaultBrowserPath(), "http://stackoverflow.com");
private static string GetDefaultBrowserPath()
{
string key = @"htmlfile\shell\open\command";
RegistryKey registryKey =
Registry.ClassesRoot.OpenSubKey(key, false);
// get default browser path
return ((string)registryKey.GetValue(null, null)).Split('"')[1];
}
It always returns Internet Explorer but not my default which is Firefox. 它总是返回Internet Explorer,但不返回默认值Firefox。 I tried it on several computers... 我在几台计算机上尝试过...
I don't care which way to call the link in the default browser, but it has to be the default 我不在乎哪种方式来调用默认浏览器的链接,但它必须是默认
Have you tried just running: 您是否尝试过仅运行:
Process.Start("http://stackoverflow.com");
My test application (below) opens the site in my default browser: 我的测试应用程序(如下)在默认浏览器中打开网站:
using System;
using System.Diagnostics;
namespace ProcessStartSample
{
class Program
{
static void Main(string[] args)
{
Process.Start("http://stackoverflow.com");
}
}
}
In other words, let the operating system do the heavy work of working out what the users default browser is for you! 换句话说,让操作系统进行繁重的工作来确定用户的默认浏览器适合您! =) =)
Just Try this :) 只是尝试这个:)
Process.Start("http://stackoverflow.com");
And if you want to find your default browser you should open HKEY_CLASSES_ROOT\\http\\shell\\open\\command\\default
key. 如果要查找默认浏览器,则应打开HKEY_CLASSES_ROOT\\http\\shell\\open\\command\\default
键。
Please pay attention "http" not "htmlFile" 请注意“ http”而不是“ htmlFile”
EDIT: 编辑:
CODE: 码:
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command", false);
string value = registryKey.GetValue("").ToString();
Windows will start the default browser on the user's system for you automatically if you just specify the URL to open: 如果您仅指定要打开的URL,则Windows将自动为您启动用户系统上的默认浏览器:
Process.Start("http://www.google.com/");
No need for any fancy Registry trickery, unless you are trying to ascertain which browser is set as the default. 除非您试图确定将哪个浏览器设置为默认浏览器,否则不需要花哨的注册表技巧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.