启动默认浏览器 - Windows [英] Start Default Browser - Windows

查看:46
本文介绍了启动默认浏览器 - Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当像这样启动默认浏览器时:

When starting the default browser like this:

        Dim trgt1 As String = "http://www.vbforums.com/showthread.php?t=612471"
        pi.FileName = trgt1
        System.Diagnostics.Process.Start(pi)

打开页面大约需要 40 秒.

It takes about 40 seconds to open the page.

如果我这样做,虽然这不是默认浏览器

If I do it like this, though this isn't the default browser

        Dim trgt1 As String = "http://www.vbforums.com/showthread.php?t=612471"
        pi.Arguments = trgt1
        pi.FileName = "iexplore.exe" 'or firefox.exe
        System.Diagnostics.Process.Start(pi)

它立即打开.这是错误还是功能?我已经将 IE 和 FireFox 设置为默认浏览器进行了尝试.

it opens immediately. Is this a bug or a feature? I have tried this with both IE and FireFox set to be the default browser.

推荐答案

1

Windows 正在通过注册表寻找合适的应用程序来打开文档(通过 explorer.exe).

1

Windows is running through the registry looking for an appropriate application to open the document with (via explorer.exe).

您明确告诉 windows 使用 xxx.exe 打开文档.

You are explicitly telling windows to use xxx.exe to open the document.

移动目标的更新:;-)

它如此缓慢的原因是您指定的 Url 看起来并不像它知道如何使用浏览器或其他方式打开的任何东西,并且必须使用蛮力来确定这一点.

The reason it is so slow is that the Url you are specifying doesn't look like anything it knows how to open, with a browser or otherwise, and has to employ brute force in determining this.

<打击>如果您想使用默认浏览器加快启动速度,请从 HKEY_CURRENT_USER\Software\Classes\http\shell\open\command 获取它并使用 #2.

If you wan to speed up launching with the default browser, get it from HKEY_CURRENT_USER\Software\Classes\http\shell\open\command and use #2.

使用该函数获取默认浏览器路径

Use this function to retrieve path of default browser

/// <summary>
/// Reads path of default browser from registry
/// </summary>
/// <returns></returns>
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];
}

在默认浏览器中从 C# 程序中打开 URL.

Opens URL in default browser from within the C# program.

string defaultBrowserPath = GetDefaultBrowserPath();

try
{
   // launch default browser
   Process.Start(defaultBrowserPath, "http://www.yahoo.com");
}
catch (Exception exp)
{
   MessageBox.Show(exp.Message);
}

在 C# 程序中的默认浏览器的单独实例中打开 URL.

Opens URL in separate instance of default browser from within the C# program.

// open URL in separate instance of default browser
Process p = new Process();
p.StartInfo.FileName = GetDefaultBrowserPath();
p.StartInfo.Arguments = "http://www.yahoo.com";
p.Start();

来自这篇博文

这篇关于启动默认浏览器 - Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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