Process.Start cannot find http://www.microsoft.com

Sam of Simple Samples 5,541 Reputation points
2023-09-24T00:57:37.2166667+00:00

See Use Visual C# method to start browser. The following is the sample code modified for a console program.

string target = "http://www.microsoft.com";
try
{
	System.Diagnostics.Process.Start(target);
}
catch (System.ComponentModel.Win32Exception noBrowser)
{
	if (noBrowser.ErrorCode == -2147467259)
		Console.WriteLine(noBrowser.Message);
}
catch (System.Exception other)
{
	Console.WriteLine(other.Message);
}

When I execute that I get:

An error occurred trying to start process 'http://www.microsoft.com'

I do not understand why. The code should work. Why I am getting that error?

The original code I am using is from Hyperlink columns: displaying the link in a browser | Programming pages. That code works except for the error above.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,836 questions
0 comments No comments
{count} votes

Accepted answer
  1. KOZ6.0 6,395 Reputation points
    2023-09-24T01:57:48.52+00:00

    The default value of the UseShellExecute property has changed.

    https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute

    That sample is for .NET Framework.
    For .NET Core or .NET please do the following:

    using System.Diagnostics;
    
    string target = "http://www.microsoft.com";
    
    var info = new ProcessStartInfo {
        FileName = target,
        UseShellExecute = true
    };
    Process.Start(info);
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.