Shell to a new browser to open a URL-VBForums
Results 1 to 24 of 24

Thread: Shell to a new browser to open a URL

  1. #1

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Shell to a new browser to open a URL

    In .NET, you can navigate to a website, simply by typing

    process.start("www.vbforums.com")

    but the problem with this, is that it will open vbforums website in a browser window you already have open...

    There is no way to specify to open a new instance of IE (or another webbrowser)

    You could simply launch IE with the website as a commandline arg, but what if the user doesn't want to use IE? It is better to not depend on a specific browser...

    My code simply creates a temporary HTM file, then finds what exe is associated with HTM files on the system, and launches that browser and navigates to the page.

    http://www.vbforums.com/attachment.p...chmentid=33874
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  2. #2
    New Member
    Join Date
    Jul 2005
    Posts
    1

    Re: Shell to a new browser to open a URL

    why don't use this command

    shell "explorer.exe http://vbforums.com"

  3. #3

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Shell to a new browser to open a URL

    Quote Originally Posted by h4finger
    why don't use this command

    shell "explorer.exe http://vbforums.com"
    because that limits the functionality to ONLY internet explorer, and assumes the user has IE installed as a browser. While it is true that IE must be installed on new windows OS (I think 2k and higher) because it is integrated into the windows shell, it is still possible to disable it as a webbrowser for those who don't like IE (or its restricted as a company policy)

    This code will shell your DEFAULT browser, which means if you use firefox, netscape, opera, etc... this will shell THAT browser to the desired page.

    make sense?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    95,448

    Re: Shell to a new browser to open a URL

    Just a point of clarification. If IE is your default browser and you call Process.Start and pass it only a URL, its behaviour depends on the "Reuse windows for launching shortcuts" option on the Advanced tab of the Internet Options dialogue. If that option is ticked then a current window will used to display the new URL if one is open. If that option is not ticked then a new window will always be opened for the new URL whether there is already a window open or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  5. #5
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: Shell to a new browser to open a URL

    I just tested process.start in my vb.net 2002... and FireFox opened ... my default browser

  6. #6

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Shell to a new browser to open a URL

    and? that is normal functionality
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: Shell to a new browser to open a URL

    i suppose you could also use the default browser value thats stored in the registry under this key ...
    HKEY_CLASSES_ROOT\htmlfile\shell\open\command ( the ' Default ' key ) to open your browser with the default rather than IE
    in that case i'd do something like this ...
    VB Code:
    1. [COLOR=Blue]Private Sub[/COLOR] Button1_Click([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Button1.Click
    2.         [COLOR=Green]'/// path to default webbrowser in registry...[/COLOR]
    3.         [COLOR=Blue]Dim[/COLOR] browserKey [COLOR=Blue]As[/COLOR] Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("htmlfile\shell\open\command", [COLOR=Blue]False[/COLOR])
    4.        [COLOR=Green] '/// get the actuall path from between the " "[/COLOR]
    5.         [COLOR=Blue]Dim[/COLOR] defaultBrowser [COLOR=Blue]As String[/COLOR] = [COLOR=Blue]DirectCast[/COLOR](browserKey.GetValue([COLOR=Blue]Nothing[/COLOR], [COLOR=Blue]Nothing[/COLOR]), [COLOR=Blue]String[/COLOR]).Split([COLOR=Blue]Chr[/COLOR](34))(1)
    6.         [COLOR=Green]'/// open the default browser, with the specified path...[/COLOR]
    7.         launchBrowser(defaultBrowser, "http://msn.co.uk/")
    8.  
    9.     [COLOR=Blue]End Sub[/COLOR]
    10.  
    11.     [COLOR=Blue]Private Sub[/COLOR] launchBrowser([COLOR=Blue]ByVal[/COLOR] browser [COLOR=Blue]As String[/COLOR], [COLOR=Blue]ByVal[/COLOR] url [COLOR=Blue]As String[/COLOR])
    12.         [COLOR=Blue]Try[/COLOR]
    13.             Process.Start(browser, url)
    14.         [COLOR=Blue]Catch[/COLOR] ex [COLOR=Blue]As[/COLOR] Exception
    15.             MessageBox.Show(ex.Message)
    16.         [COLOR=Blue]End Try[/COLOR]
    17.     [COLOR=Blue]End Sub[/COLOR]
    goes to show there are various ways
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  8. #8
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: Shell to a new browser to open a URL

    I have a followup question to this, the URL I'd like to be able to browse to is different depending on the customer number the form is looking at...I have the unique URLS in a a field in my table..how do I tell this shell command to use *that* specific URL?


    Quote Originally Posted by dynamic_sysop
    i suppose you could also use the default browser value thats stored in the registry under this key ...
    HKEY_CLASSES_ROOT\htmlfile\shell\open\command ( the ' Default ' key ) to open your browser with the default rather than IE
    in that case i'd do something like this ...
    VB Code:
    1. [COLOR=Blue]Private Sub[/COLOR] Button1_Click([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Button1.Click
    2.         [COLOR=Green]'/// path to default webbrowser in registry...[/COLOR]
    3.         [COLOR=Blue]Dim[/COLOR] browserKey [COLOR=Blue]As[/COLOR] Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("htmlfile\shell\open\command", [COLOR=Blue]False[/COLOR])
    4.        [COLOR=Green] '/// get the actuall path from between the " "[/COLOR]
    5.         [COLOR=Blue]Dim[/COLOR] defaultBrowser [COLOR=Blue]As String[/COLOR] = [COLOR=Blue]DirectCast[/COLOR](browserKey.GetValue([COLOR=Blue]Nothing[/COLOR], [COLOR=Blue]Nothing[/COLOR]), [COLOR=Blue]String[/COLOR]).Split([COLOR=Blue]Chr[/COLOR](34))(1)
    6.         [COLOR=Green]'/// open the default browser, with the specified path...[/COLOR]
    7.         launchBrowser(defaultBrowser, "http://msn.co.uk/")
    8.  
    9.     [COLOR=Blue]End Sub[/COLOR]
    10.  
    11.     [COLOR=Blue]Private Sub[/COLOR] launchBrowser([COLOR=Blue]ByVal[/COLOR] browser [COLOR=Blue]As String[/COLOR], [COLOR=Blue]ByVal[/COLOR] url [COLOR=Blue]As String[/COLOR])
    12.         [COLOR=Blue]Try[/COLOR]
    13.             Process.Start(browser, url)
    14.         [COLOR=Blue]Catch[/COLOR] ex [COLOR=Blue]As[/COLOR] Exception
    15.             MessageBox.Show(ex.Message)
    16.         [COLOR=Blue]End Try[/COLOR]
    17.     [COLOR=Blue]End Sub[/COLOR]
    goes to show there are various ways

  9. #9
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Shell to a new browser to open a URL

    This is the code I use in my Login Password Manager (Go to Site Button) and
    it opens a new browser instance for me:

    Code:
    
              Dim p As New Process()
              p.StartInfo.FileName = GetDefaultBrowser()
              p.StartInfo.Arguments = targetURL
              p.Start()
    
    
    Friend Function GetDefaultBrowser() As String
        Dim browser As String = [String].Empty
        Dim key As Microsoft.Win32.RegistryKey = Nothing
        Dim Quote As String = Chr(34)
        Try
    
          key = My.Computer.Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
    
          ' trim off quotes
          browser = key.GetValue(Nothing).ToString().ToLower().Replace(Quote, "")
          If Not browser.EndsWith("exe") Then
            ' get rid of everything after the 'exe'
            browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
    
          End If
    
        Finally
          If key IsNot Nothing Then
            key.Close()
          End If
        End Try
    
        Return browser
    
      End Function

  10. #10
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: Shell to a new browser to open a URL

    Thanks kleinma it worked perfectly!
    As an aside, is there a way to hide the default browser
    using this code? I am using it to set a cookie only but do
    not want it visible if possible.

  11. #11

  12. #12
    Junior Member
    Join Date
    Jul 2010
    Posts
    26

    Re: Shell to a new browser to open a URL

    Code:
            Dim webAddress As String = "http://www.vbforums.com"
            Process.Start(webAddress)
    This works for me, also brings up the browser.

  13. #13
    Member
    Join Date
    Dec 2010
    Posts
    44

    Re: Shell to a new browser to open a URL

    Quote Originally Posted by Imperoto View Post
    Code:
            Dim webAddress As String = "http://www.vbforums.com"
            Process.Start(webAddress)
    This works for me, also brings up the browser.
    This worked great, Thanks !

  14. #14

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Shell to a new browser to open a URL

    The original code here was to address shelling to a NEW INSTANCE of the DEFAULT BROWSER. Yes you can use process.start passing a URL, but that will use an existing instance of the default browser if that is open. Likewise calling process.start passing in a specific browser exe and a URL as an argument is not guaranteed to be the default browser on the system.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  15. #15
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Smile Re: Shell to a new browser to open a URL

    Hi all,
    i have query, i want to open browser only with title bar(without address,without menubar, without fav..etc...)..

    any help me in this..

  16. #16
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Re: Shell to a new browser to open a URL

    By using .."Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double
    "

  17. #17
    New Member
    Join Date
    May 2012
    Posts
    2

    Re: Shell to a new browser to open a URL

    I'm trying to build a small test harness that makes it easy to open various internal websites in whatever browser I want. For IE, Chrome, Firefox and things, I'm doing this, and it works fine...

    Dim p As New Process
    p.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    p.StartInfo.FileName = "firefox"
    p.StartInfo.Arguments = theUrl
    p.Start()

    Works fine, the browser opens and the requested URL is loaded automatically.

    The problem I've got is that it doesn't work with Opera.

    Anyone know how to get this working?

    I've tried using the older Shell() command but that doesn't work either.

    I've created a desktop shortcut and confirmed that Opera does actually support this, i.e. setting the shortcut to "c:\path\to\opera.exe www.vbforums.com" does actually work. So I'm not sure why I can't get VB to do the same thing.

  18. #18
    New Member
    Join Date
    May 2012
    Posts
    2

    Re: Shell to a new browser to open a URL

    ... I should have mentioned that when I run the code against Opera, it simply opens a new Opera instance but no URL gets loaded.

  19. #19
    New Member
    Join Date
    Jan 2013
    Posts
    2

    Re: Shell to a new browser to open a URL

    Hello.
    I have a Question:

    Is it Possible to open a new URL in a Browser Window with a click on a button?
    EGG: i have 10 buttons, on every Button is an other URL.
    I want it like, if i click a button, the Browser in my forum opens this URL, and if i click another Button, the same Browser opens this URL.

    Is this possible?

  20. #20
    New Member
    Join Date
    Jan 2013
    Posts
    2

    Re: Shell to a new browser to open a URL

    I'm sry i cannot find the edit Button.

    I dont mean Forum, i mean: FORM. eg: forum1

  21. #21
    Junior Member
    Join Date
    Apr 2012
    Posts
    20

    Re: Shell to a new browser to open a URL

    Quote Originally Posted by Emcrank View Post
    Code:
    Process.Start("explorer.exe", "www.google.com")
    Works fine for me
    Just a nice little sub, some people may like: (but its not as good as a 12" pizza sub!)

    vb.net Code:
    1. Private Sub NavigateWebURL(ByVal URL As String, Optional browser As String = "default")
    2.  
    3.     If Not (browser = "default") Then
    4.         Try
    5.             '// try set browser if there was an error (browser not installed)
    6.             Process.Start(browser, URL)
    7.         Catch ex As Exception
    8.             '// use default browser
    9.             Process.Start(URL)
    10.         End Try
    11.  
    12.     Else
    13.         '// use default browser
    14.         Process.Start(URL)
    15.  
    16.     End If
    17.  
    18. End Sub

    ---
    Call: will open www.google.com in Firefox if it is installed on that PC.

    vb.net Code:
    1. NavigateWebURL("http://www.google.com", "Firefox") '// safari Firefox chrome etc

    ---
    Call: will open www.google.com in default browser.

    vb.net Code:
    1. NavigateWebURL("http://www.google.com", "default")

    OR

    vb.net Code:
    1. NavigateWebURL("http://www.google.com")

    The post: http://stackoverflow.com/questions/6...wser/#15192260
    Last edited by o3xa; Mar 3rd, 2013 at 06:06 PM.

  22. #22
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,158

    Re: Shell to a new browser to open a URL

    As others have said to shell it using the registry would be better to find out what opens a html file... HKClassesRoot\.htm from memory (on osx atm)

    Kris

  23. #23
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    Re: Shell to a new browser to open a URL

    I know this is an old post but this may help someone.... The code o3xa put is a nice little piece of code but it will not work if your webpage is hosted on and IIS server as process.start will open the process on the server. funny when testing in Visual Studio the button works but when you publish the server it does not. the only way I could find to do this is the use the page.client script function
    Code:
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            'Opens new browser and passes the variable ulr for the search. 
            Dim url = "http://google.com/search?q=" & TextBox1.Text
            Page.ClientScript.RegisterStartupScript(GetType(Page), url, "window.open('" + url + "','');", True) End Sub
    Last edited by Troy Mac; Sep 23rd, 2013 at 02:38 PM. Reason: Change quotes to code brackets
    TMacPherson
    MIS Systems Engineer
    t_macpherson@yahoo.com


  24. #24
    New Member
    Join Date
    Dec 2015
    Posts
    1

    Re: Shell to a new browser to open a URL

    Dim strLink As String = "www.google.com"
    Dim chromelocation As String = "D:\Application\chrome.exe"
    Process.Start(chromelocation, strLink)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.