Launch a web page with your default browser

Tuttomax

New member
Joined
Feb 9, 2024
Messages
1
Programming Experience
Beginner
I would need to write a simple console-type exe which, upon passing a parameter from the command line, starts a URL with the default browser. No problem for the parameter passing, but launching a url puts me in difficulty...

These are some of the code I used, but of course it doesn't work

Imports System
Module Program

Sub Main(args As String())

Dim par() As String = Environment.GetCommandLineArgs()

Process.Start("https://url/Url/Url/" & par(1))

Console.WriteLine(par(1))


End Sub

End Module


.. Thank you
 
Try this:
VB.NET:
Process.Start(New ProcessStartInfo("http...") With {.UseShellExecute = True})
 
You can also try the following two methods:

---

Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = url
p.Start()

---

Process.Start("cmd", "/C start" + " " + url)
 
The reason that your code has worked previously but not recently is probably because of the difference between .NET Framework and .NET Core (.NET 5 and later are based on .NET Core). As has been shown, you need the UseShellExecute property of the ProcessStartInfo to be set to True. That is the default in .NET Framework but it's set to False by default in .NET Core. That information is in the relevant documentation so this is a perfect example of why you should always read the relevant documentation first when you have an issue. We're still here if you can't find what you need to or can't understand what you find but you should always look first and try to solve the problem yourself. Even if you can't find the information you need to fix the current issue, I've lost count of the number of times that I've found information that was useful later when reading documentation. For instance, if you'd already read about the Process class, etc, then you'd likely already know about the property and the change in its default value.
 
Back
Top