To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > VBForums CodeBank > CodeBank - Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Feb 4th, 2005, 03:34 PM   #1
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,435
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
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 VB.NET 2010/.NET 2.0 through 4.0 * 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=-
kleinma is offline   Reply With Quote
Old Jul 18th, 2005, 08:49 PM   #2
h4finger
New Member
 
Join Date: Jul 05
Posts: 1
h4finger is an unknown quantity at this point (<10)
Re: Shell to a new browser to open a URL

why don't use this command

shell "explorer.exe http://vbforums.com"
h4finger is offline   Reply With Quote
Old Jul 19th, 2005, 09:07 AM   #3
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,435
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
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 VB.NET 2010/.NET 2.0 through 4.0 * 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=-
kleinma is offline   Reply With Quote
Old Sep 6th, 2005, 10:48 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 60,536
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
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.
__________________

2007, 2008, 2009, 2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET
jmcilhinney is offline   Reply With Quote
Old Sep 13th, 2005, 05:09 PM   #5
gigemboy
"The" RedHeadedLefty
 
gigemboy's Avatar
 
Join Date: Aug 05
Location: College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
Posts: 4,484
gigemboy is a glorious beacon of light (400+)gigemboy is a glorious beacon of light (400+)gigemboy is a glorious beacon of light (400+)gigemboy is a glorious beacon of light (400+)gigemboy is a glorious beacon of light (400+)
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
gigemboy is offline   Reply With Quote
Old Sep 14th, 2005, 08:17 AM   #6
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,435
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
Re: Shell to a new browser to open a URL

and? that is normal functionality
__________________
Using VB.NET 2010/.NET 2.0 through 4.0 * 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=-
kleinma is offline   Reply With Quote
Old Sep 16th, 2005, 04:08 PM   #7
dynamic_sysop
Frenzied Member
 
dynamic_sysop's Avatar
 
Join Date: Jun 03
Location: Ashby, Leicestershire.
Posts: 1,091
dynamic_sysop has a spectacular aura about (150+)dynamic_sysop has a spectacular aura about (150+)
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.     [color=Blue]End Sub[/color]
  9.     [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])
  10.         [color=Blue]Try[/color]
  11.             Process.Start(browser, url)
  12.         [color=Blue]Catch[/color] ex [color=Blue]As[/color] Exception
  13.             MessageBox.Show(ex.Message)
  14.         [color=Blue]End Try[/color]
  15.     [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]
dynamic_sysop is offline   Reply With Quote
Old Jan 31st, 2008, 06:12 PM   #8
mregina
New Member
 
Join Date: Jan 08
Posts: 3
mregina is an unknown quantity at this point (<10)
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.     [color=Blue]End Sub[/color]
  9.     [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])
  10.         [color=Blue]Try[/color]
  11.             Process.Start(browser, url)
  12.         [color=Blue]Catch[/color] ex [color=Blue]As[/color] Exception
  13.             MessageBox.Show(ex.Message)
  14.         [color=Blue]End Try[/color]
  15.     [color=Blue]End Sub[/color]
goes to show there are various ways
mregina is offline   Reply With Quote
Old Feb 9th, 2008, 05:41 PM   #9
ZeBula8
Fanatic Member
 
ZeBula8's Avatar
 
Join Date: Oct 02
Posts: 547
ZeBula8  is on a distinguished road (40+)
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
ZeBula8 is offline   Reply With Quote
Old Sep 13th, 2008, 02:16 AM   #10
cmmorris1
Addicted Member
 
Join Date: May 08
Posts: 133
cmmorris1 is an unknown quantity at this point (<10)
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.
cmmorris1 is offline   Reply With Quote
Old Jul 4th, 2010, 04:03 PM   #11
Emcrank
Fanatic Member
 
Emcrank's Avatar
 
Join Date: Jan 09
Posts: 555
Emcrank is an unknown quantity at this point (<10)
Re: Shell to a new browser to open a URL

Code:
Process.Start("explorer.exe", "www.google.com")
Works fine for me
__________________
  • I appreciate any reply's
  • If I helped you in any way, even just a bit. Rate my post with the button on the left()
- - - - - - - -



- - - - - - - - - - - - -
Website
eDev Software

On-Going Projects
1.Tinternet
- - - - - - - - - - - - -
My Useful Links:.NET Framework Class Library | [Internet Explorer Version]Internet Reconnecter | [Mozilla Firefox Version]Internet Reconnecter | Auto Clicker | 30 Minute Regex Tutorial |
CodeBank(ALL):Simulate Mouse Click | HTML Viewer | EaseInstaller | Signs + Description | VB Code Snippet Maker | Read/Write .INI Files | Movable Form Without Titlebar | Check ifFirstRun | Create App Thread | Volume Control Class | Custom Wait Function | Emcranks Auto Updater | System-Wide Hotkeys [Virtual Key Codes] | Get Filename From Download URL | Zipping/Unzipping Using Shell32.dll | Import My.Settings From Previous Build | WebBrowser Control: Delete History | Simple Sound Recorder [mciSendString Commands] | App Trial Code | WebBrowser Control: Get Favicon.ico | Generate Random String | Manipulate Files Using Wildcards |

Last edited by Emcrank; Jul 17th, 2010 at 11:47 AM.
Emcrank is offline   Reply With Quote
Old Jul 17th, 2010, 11:24 AM   #12
Imperoto
Junior Member
 
Join Date: Jul 10
Posts: 26
Imperoto is an unknown quantity at this point (<10)
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.
Imperoto is offline   Reply With Quote
Reply

Go Back   VBForums > VBForums CodeBank > CodeBank - Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:56 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.