I want to make my WPF application open the default browser and go to a certain web page. How do I do that?
9 Answers
For desktop versions of .NET:
System.Diagnostics.Process.Start("http://www.webpage.com");
For .NET Core, the default for ProcessStartInfo.UseShellExecute
has changed from true
to false
, and so you have to explicitly set it to true
for this to work:
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "http://www.webpage.com",
UseShellExecute = true
});
To further complicate matters, this property cannot be set to true
for UWP apps (so none of these solutions are usable for UWP).

- 68,759
- 7
- 102
- 136

- 20,376
- 9
- 50
- 82
-
3I used this as well, but now it turns out this doesn't work with UAC. In my application I have this in the manifest
When I run the app under Windows 8 (where you cannot disable UAC anymore), I get the following exception when opening a web page: Win32Exception (0x80004005): Class not registered at System.Diagnostics.Process.StartWithShellExecuteEx – lvmeijer Jul 13 '12 at 15:39 -
This effect won't happen when I change requireAdministrator to asInvoker. But then the app isn't elevated :-( – lvmeijer Jul 13 '12 at 15:46
Accepted answer no longer works on .NET Core 3. To make it work, use the following method:
var psi = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start (psi);

- 1,573
- 12
- 23
I've been using this line to launch the default browser:
System.Diagnostics.Process.Start("http://www.google.com");

- 12,106
- 12
- 71
- 90
While a good answer has been given (using Process.Start
), it is safer to encapsulate it in a function that checks that the passed string is indeed a URI, to avoid accidentally starting random processes on the machine.
public static bool IsValidUri(string uri)
{
if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute))
return false;
Uri tmp;
if (!Uri.TryCreate(uri, UriKind.Absolute, out tmp))
return false;
return tmp.Scheme == Uri.UriSchemeHttp || tmp.Scheme == Uri.UriSchemeHttps;
}
public static bool OpenUri(string uri)
{
if (!IsValidUri(uri))
return false;
System.Diagnostics.Process.Start(uri);
return true;
}

- 17,602
- 7
- 105
- 102
Here is my complete code how to open.
there are 2 options:
open using default browser (behavior is like opened inside the browser window)
open through default command options (behavior is like you use "RUN.EXE" command)
open through 'explorer' (behavior is like you wrote url inside your folder window url)
[optional suggestion] 4. use iexplore process location to open the required url
CODE:
internal static bool TryOpenUrl(string p_url)
{
// try use default browser [registry: HKEY_CURRENT_USER\Software\Classes\http\shell\open\command]
try
{
string keyValue = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\http\shell\open\command", "", null) as string;
if (string.IsNullOrEmpty(keyValue) == false)
{
string browserPath = keyValue.Replace("%1", p_url);
System.Diagnostics.Process.Start(browserPath);
return true;
}
}
catch { }
// try open browser as default command
try
{
System.Diagnostics.Process.Start(p_url); //browserPath, argUrl);
return true;
}
catch { }
// try open through 'explorer.exe'
try
{
string browserPath = GetWindowsPath("explorer.exe");
string argUrl = "\"" + p_url + "\"";
System.Diagnostics.Process.Start(browserPath, argUrl);
return true;
}
catch { }
// return false, all failed
return false;
}
and the Helper function:
internal static string GetWindowsPath(string p_fileName)
{
string path = null;
string sysdir;
for (int i = 0; i < 3; i++)
{
try
{
if (i == 0)
{
path = Environment.GetEnvironmentVariable("SystemRoot");
}
else if (i == 1)
{
path = Environment.GetEnvironmentVariable("windir");
}
else if (i == 2)
{
sysdir = Environment.GetFolderPath(Environment.SpecialFolder.System);
path = System.IO.Directory.GetParent(sysdir).FullName;
}
if (path != null)
{
path = System.IO.Path.Combine(path, p_fileName);
if (System.IO.File.Exists(path) == true)
{
return path;
}
}
}
catch { }
}
// not found
return null;
}
Hope i helped.

- 1
- 1

- 2,208
- 23
- 12
You cannot launch a web page from an elevated application. This will raise a 0x800004005 exception, probably because explorer.exe and the browser are running non-elevated.
To launch a web page from an elevated application in a non-elevated web browser, use the code made by Mike Feng. I tried to pass the URL to lpApplicationName but that didn't work. Also not when I use CreateProcessWithTokenW with lpApplicationName = "explorer.exe" (or iexplore.exe) and lpCommandLine = url.
The following workaround does work: Create a small EXE-project that has one task: Process.Start(url), use CreateProcessWithTokenW to run this .EXE. On my Windows 8 RC this works fine and opens the web page in Google Chrome.

- 1,022
- 13
- 14
-
2See [comment](http://stackoverflow.com/questions/1173630/how-do-you-de-elevate-privileges-for-a-child-process#comment40205343_15041823), using `Explorer.exe` to de-elevate is not supported: "Unfortunately, the Windows Shell team has replied that the current behavior of "Explorer.exe AppName.exe" is a bug and may not work in future updates/versions of Windows. Applications should not rely upon it." – Carl Walsh Dec 07 '15 at 08:18
I have the solution for this due to I have a similar problem today.
Supposed you want to open http://google.com from an app running with admin priviliges:
ProcessStartInfo startInfo = new ProcessStartInfo("iexplore.exe", "http://www.google.com/");
Process.Start(startInfo);

- 191
- 1
- 4
string target= "http://www.google.com";
try
{
System.Diagnostics.Process.Start(target);
}
catch (System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode==-2147467259)
MessageBox.Show(noBrowser.Message);
}
catch (System.Exception other)
{
MessageBox.Show(other.Message);
}