27

I'm trying to open an URL following a simple method written all over google and even MSDN. But for unknown reasons I get an Exception as follows:

Win32Exception was unhandled

Message: Application not found

Exception

Here's my code:

private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    ProcessStartInfo sInfo = new ProcessStartInfo("http://github.com/tbergeron/todoTxt");
    Process.Start(sInfo);
}

Any idea why it is failing?

Thanks a lot!

Dai
  • 141,631
  • 28
  • 261
  • 374
Tommy B.
  • 3,591
  • 14
  • 61
  • 105

4 Answers4

83

I had a similar issue trying this with .NET Core and getting a Win32Exception, I dealt with it like so:

var ps = new ProcessStartInfo("http://myurl")
{ 
    UseShellExecute = true, 
    Verb = "open" 
};
Process.Start(ps);
Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
Flatliner DOA
  • 6,128
  • 4
  • 30
  • 39
  • 3
    Thank you very much, nothing else worked in .NET Core 3. –  Sep 04 '19 at 11:23
  • 7
    [`UseShellExecute`](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute?view=netframework-4.8#property-value) by default it set to `true` in .NET Framework and to `false` in .NET Core, I guess it's a reason of exception – Pavel Anikhouski Feb 12 '20 at 09:04
  • 3
    For me, Verb= "Open" is not required, it works without. – Kino101 Mar 01 '21 at 22:10
  • 4
    Works well on .Net6.0 – Usama Aziz Sep 15 '21 at 02:09
10

This is apparently machine-specific behaviour (http://devtoolshed.com/content/launch-url-default-browser-using-c).

The linked article suggests using Process.Start("http://myurl") but catching Win32Exception and falling back to Process.Start("IExplore.exe", "http://myurl"):

try
{
  Process.Start("http://myurl");
}
catch (Win32Exception)
{
  Process.Start("IExplore.exe", "http://myurl");
}

Sadly after trying almost everything, this was the best I could do on my machine.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • You should use `catch( Win32Exception w32Ex ) when ( w32Ex.NativeErrorCode == 0x800401F5 /* CO_E_APPNOTFOUND */ )`. See my answer here: https://stackoverflow.com/a/63751559/159145 – Dai Sep 05 '20 at 07:53
1

You are looking for the string overload of Process.Start():

Process.Start("http://github.com/tbergeron/todoTxt");
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    Are you sure? I could repro your exception but calling with the string version worked well. Your machine is probably misconfigured. – David Heffernan Oct 08 '11 at 07:24
-1

Throw start in front of it, if you want to launch in the default browser:

new ProcessStartInfo("start http://github.com/tbergeron/todoTxt");
John Buchanan
  • 5,054
  • 2
  • 19
  • 17