-
Feb 4th, 2005, 04:34 PM
#1
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
-
Jul 18th, 2005, 08:49 PM
#2
New Member
Re: Shell to a new browser to open a URL
why don't use this command
shell "explorer.exe http://vbforums.com"
-
Jul 19th, 2005, 09:07 AM
#3
Re: Shell to a new browser to open a URL
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?
-
Sep 6th, 2005, 10:48 PM
#4
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.
-
Sep 13th, 2005, 05:09 PM
#5
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
-
Sep 14th, 2005, 08:17 AM
#6
Re: Shell to a new browser to open a URL
and? that is normal functionality
-
Sep 16th, 2005, 04:08 PM
#7
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:
[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
~
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]
-
Jan 31st, 2008, 07:12 PM
#8
New Member
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?
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:
[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
-
Feb 9th, 2008, 06:41 PM
#9
Fanatic Member
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
-
Sep 13th, 2008, 02:16 AM
#10
Addicted Member
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.
-
Jul 4th, 2010, 04:03 PM
#11
Fanatic Member
Re: Shell to a new browser to open a URL
Code:
Process.Start("explorer.exe", "www.google.com")
Works fine for me
Last edited by Emcrank; Jul 17th, 2010 at 11:47 AM.
-
Jul 17th, 2010, 11:24 AM
#12
Junior Member
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.
-
Dec 14th, 2010, 12:38 AM
#13
Member
Re: Shell to a new browser to open a URL
Originally Posted by Imperoto
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 !
-
Dec 17th, 2010, 12:16 PM
#14
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.
-
Apr 30th, 2012, 05:57 AM
#15
New Member
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..
-
Apr 30th, 2012, 05:59 AM
#16
New Member
Re: Shell to a new browser to open a URL
By using .."Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double
"
-
Oct 17th, 2012, 07:59 AM
#17
New Member
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.
-
Oct 17th, 2012, 08:01 AM
#18
New Member
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.
-
Jan 18th, 2013, 08:57 AM
#19
New Member
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?
-
Jan 18th, 2013, 08:58 AM
#20
New Member
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
-
Mar 3rd, 2013, 07:01 PM
#21
Junior Member
Re: Shell to a new browser to open a URL
Originally Posted by Emcrank
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:
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
Last edited by o3xa; Mar 3rd, 2013 at 07:06 PM.
-
Mar 4th, 2013, 09:52 AM
#22
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
-
Sep 23rd, 2013, 02:37 PM
#23
Hyperactive Member
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
-
Dec 21st, 2015, 05:28 AM
#24
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|