Results 1 to 7 of 7

Thread: Basic url opening in VS 2019

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    2

    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.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,914

    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.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,666

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    2

    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?

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,666

    Re: Basic url opening in VS 2019

    Quote Originally Posted by thefirstone View Post
    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

  6. #6
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    264

    Re: Basic url opening in VS 2019

    Quote Originally Posted by thefirstone View Post
    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.

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,666

    Re: Basic url opening in VS 2019

    Quote Originally Posted by VB.NET Developer View Post
    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
  •  



Click Here to Expand Forum to Full Width