# VBForums CodeBank > CodeBank - Visual Basic .NET >  Shell to a new browser to open a URL

## kleinma

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

----------


## h4finger

why don't use this command

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

----------


## kleinma

> 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?

----------


## jmcilhinney

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.

----------


## gigemboy

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

----------


## kleinma

and? that is normal functionality

----------


## 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   :Smilie:  
in that case i'd do something like this ...

VB Code:
[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
        [COLOR=Green]'/// path to default webbrowser in registry...[/COLOR]
        [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])
       [COLOR=Green] '/// get the actuall path from between the " "[/COLOR]
        [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)
        [COLOR=Green]'/// open the default browser, with the specified path...[/COLOR]
        launchBrowser(defaultBrowser, "http://msn.co.uk/")
     [COLOR=Blue]End Sub[/COLOR]
     [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])
        [COLOR=Blue]Try[/COLOR]
            Process.Start(browser, url)
        [COLOR=Blue]Catch[/COLOR] ex [COLOR=Blue]As[/COLOR] Exception
            MessageBox.Show(ex.Message)
        [COLOR=Blue]End Try[/COLOR]
    [COLOR=Blue]End Sub[/COLOR]
goes to show there are various ways   :Smilie:

----------


## mregina

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?





> 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:
> [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
>         [COLOR=Green]'/// path to default webbrowser in registry...[/COLOR]
>         [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])
>        [COLOR=Green] '/// get the actuall path from between the " "[/COLOR]
> ...

----------


## ZeBula8

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



```


          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
```

----------


## cmmorris1

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.

----------


## Emcrank

```
Process.Start("explorer.exe", "www.google.com")
```

 Works fine for me  :Smilie:

----------


## Imperoto

```
        Dim webAddress As String = "http://www.vbforums.com"
        Process.Start(webAddress)
```

This works for me, also brings up the browser.

----------


## level42

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


This worked great, Thanks  :Big Grin: !

----------


## kleinma

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.

----------


## alanka_kishore

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..

----------


## alanka_kishore

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

----------


## JoeFx

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.

----------


## JoeFx

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

----------


## Kalle801

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?

----------


## Kalle801

I'm sry i cannot find the edit Button.

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

----------


## o3xa

> ```
> 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:
Private Sub NavigateWebURL(ByVal URL As String, Optional browser As String = "default")     If Not (browser = "default") Then        Try            '// try set browser if there was an error (browser not installed)            Process.Start(browser, URL)        Catch ex As Exception            '// use default browser            Process.Start(URL)        End Try     Else        '// use default browser        Process.Start(URL)     End If End Sub

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


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

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


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

OR


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

 The post: http://stackoverflow.com/questions/6...wser/#15192260

----------


## i00

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

----------


## Troy Mac

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 


```
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
```

----------


## arexjama

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

----------

