-
Oct 6th, 2021, 01:11 PM
#1
Thread Starter
New Member
Basic url opening in VS 2019
I just installed VS 2019 and created a simple form. I am trying to have a linklable or button open a web page but I get an exception error. I'm pretty sure it is a missing a module or something. I have tried many example from many forums but no matter what code it is I get the same error.
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim url As String = "http://www.google.com"
Process.Start(url)
end sub
System.ComponentModel.Win32Exception: 'The system cannot find the file specified.'
Last edited by dday9; Oct 6th, 2021 at 03:35 PM.
-
Oct 6th, 2021, 03:39 PM
#2
Re: Basic url opening in VS 2019
If you do not have a default application setup for the HTTP protocol, I believe you would get the exception. To test, bring up the run prompt (windows key + r), enter the URL, and hit OK. I would expect that you'd get the same exception.
-
Oct 6th, 2021, 04:19 PM
#3
Re: Basic url opening in VS 2019
Here is an example targeting Chrome browser
Code:
Imports Microsoft.Win32
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
if Not IsChromeAvailable
OpenPageButton.Enabled = False
End If
End Sub
Private Sub OpenPageButton_Click(sender As Object, e As EventArgs) Handles OpenPageButton.Click
if Not string.IsNullOrWhiteSpace(PageTextBox.Text)
OpenLink(PageTextBox.Text)
End If
End Sub
End Class
''' <summary>
''' For opening a page in Chrome browser
''' </summary>
''' <remarks>
''' * If Chrome.exe was in the path this class is not needed.
''' * If the user running the app does not have read permissions to the registry
''' a runtime exception will be thrown.
''' </remarks>
Public Module ChromeLauncher
Private Const ChromeAppKey As String =
"\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"
Public ReadOnly Property ChromeAppFileName() As String
Get
Return DirectCast(
If(Registry.GetValue($"HKEY_LOCAL_MACHINE{ChromeAppKey}",
"",
Nothing),
Registry.GetValue($"HKEY_CURRENT_USER{ChromeAppKey}", "", Nothing)),
String)
End Get
End Property
Public ReadOnly Property IsChromeAvailable() As Boolean
get
Return Not String.IsNullOrWhiteSpace(ChromeAppFileName)
End Get
End Property
Public Sub OpenLink( url As String)
Dim FileName As String = ChromeAppFileName
If String.IsNullOrWhiteSpace(FileName) Then
Throw New Exception("Could not find chrome.exe!!!")
End If
Process.Start(FileName, url)
End Sub
End Module
-
Oct 7th, 2021, 10:40 AM
#4
Thread Starter
New Member
Re: Basic url opening in VS 2019
Ok so that worked. I guess I need to determine what browsers are available on the clients computer correct?
-
Oct 7th, 2021, 11:18 AM
#5
Re: Basic url opening in VS 2019
Originally Posted by thefirstone
Ok so that worked. I guess I need to determine what browsers are available on the clients computer correct?
If using .NET Core consider the following NuGet package (source)
Install-Package MintPlayer.PlatformBrowser
Code:
Option Infer On
Dim browsers = PlatformBrowser.GetInstalledBrowsers()
For Each browser In browsers
Debug.WriteLine($"Browser: {browser.Name}")
Debug.WriteLine($"Executable: {browser.ExecutablePath}")
Debug.WriteLine($"Icon path: {browser.IconPath}")
Debug.WriteLine($"Icon index: {browser.IconIndex}")
Debug.WriteLine("")
Next
-
Oct 7th, 2021, 11:19 AM
#6
Hyperactive Member
Re: Basic url opening in VS 2019
Originally Posted by thefirstone
Ok so that worked. I guess I need to determine what browsers are available on the clients computer correct?
Not neccessarily. The most simplest approach is to use
Code:
Process.Start (https://www.google.com)
and it opens that website in your default browser.
btw, if your problem has been already solved, under thread tools at the top of this page click on mark it as resolved item. Also,
(see below - bold text).
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Oct 7th, 2021, 12:04 PM
#7
Re: Basic url opening in VS 2019
Originally Posted by VB.NET Developer
Not neccessarily. The most simplest approach is to use
Code:
Process.Start (https://www.google.com)
and it opens that website in your default browser.
btw, if your problem has been already solved, under thread tools at the top of this page click on mark it as resolved item. Also,
(see below - bold text).
Note the OP has already done this in the initial post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|