opening internet browser

  • Thread starter Thread starter Alucard
  • Start date Start date
A

Alucard

Hello all,
I would like to know how to programmatically
open the system default browser with a specified URL?

For example, clicking a button to open up a browser window loaded with a
specified URL.
 
Hi,

Try this: Process.Start (http://www.google.com);

Hello all,
I would like to know how to programmatically
open the system default browser with a specified URL?

For example, clicking a button to open up a browser window loaded with a
specified URL.
 
Hello all,
I would like to know how to programmatically
open the system default browser with a specified URL?

For example, clicking a button to open up a browser window loaded with a
specified URL.

Here is how to open the default browser

using System.Diagnostics;
using Microsoft.Win32;

On the button click you do
{
System.Diagnostics.ProcessStartInfo parms = new ProcessStartInfo
(getDefaultBrowser(),"http://home.comcast.net/~l_and_l");
System.Diagnostics.Process.Start(parms);
}
Where

private string getDefaultBrowser()
{
string browser = string.Empty;
RegistryKey key = null;
try
{
key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open
\command", false);

//trim off quotes
browser = key.GetValue(null).ToString().ToLower().Replace("\"",
"");
if (!browser.EndsWith("exe"))
{
//get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe")+
4);
}
}
finally
{
if (key != null) key.Close();
}
return browser;
}
 
You can only call executables (.exe) if you set UseShellExecute to
false. To run a dll when UseShellExecute is false, you can use
"rundll32" to do this as in:

Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo =
new ProcessStartInfo("rundll32.exe" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments= "url.dll ,FileProtocolHandler
www.microsoft.com";
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

Warning: If you try to start the process "http://www.microsoft.com" from
a [MTAThreaded] application with UseShellExecute set to true, your
[MTAThreaded] application will throw an exception.

Regards,
Jeff
 
Back
Top