开发者

DefaultBrowser from Registry doesn't work

I'm trying to open a url in the default browser. Obviously I thought that Shell Exec will open it in the default browser but it doesn't.

Then I tried explicit:

Process.Start(GetDefaultBrow开发者_如何学GoserPath(), "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. 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.

Please pay attention "http" not "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:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜