Launch default browser - Windows

When starting the default browser, for example:

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

It takes about 40 seconds to open the page.

If I do it like this, although this is not 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)

it opens immediately. Is this a bug or a function? I tried this, and both IE and FireFox were the default browser.

+3
source share
2 answers

1

Windows starts through the registry, looking for a suitable application to open the document with (via explorer.exe).

2

You explicitly tell windows to use xxx.exe to open the document.

Update for a moving target :; -)

, , , Url, , , , , .

, HKEY_CURRENT_USER\Software\Classes\http\shell\open\command # 2.a >

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

URL- #.

string defaultBrowserPath = GetDefaultBrowserPath();

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

URL- #.

// 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();

+3

. ,

string key = @"htmlfile\shell\open\command";

, IE, Chrome . , , firefox, , , , , IE .

, , .

process.start(url), , . ! MS ...

0

Source: https://habr.com/ru/post/1742649/


All Articles