check the default browser
Hi there,
how will i check a default browser?
i will open a site and i will opened it in IE only.so, i need to check first if the default browser is IE.if not,then i will open it in IE..if IE is not available then i will show a message that IE is not installed in your computer..
also,if IE is already opened then i will launch the website on the next tab in IE browser...
i used process.start("iexplorer.exe",website) and it will create new instance of IE everytime i open a site..
thank you..
Re: check the default browser
Well when you start a website you are using "http". So how does Windows know what program to associate with this class? If you navigate in your registry to:
Code:
HKEY_CLASSES_ROOT\http\shell\open\command
You will see the default command line that is run, along with which program will run it. For me I get:
Code:
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1"
So... Firefox is going to handle my requests for http. You can use the managed registry classes that the .NET framework provides to check these settings.
Re: check the default browser
Quote:
Originally Posted by
ForumAccount
Well when you start a website you are using "http". So how does Windows know what program to associate with this class? If you navigate in your registry to:
Code:
HKEY_CLASSES_ROOT\http\shell\open\command
hi, i cannot see "http" under HKEY_CLASSES_ROOT in my registry..
Re: check the default browser
Quote:
Originally Posted by
[gja]
hi, i cannot see "http" under HKEY_CLASSES_ROOT in my registry..
Try:
Quote:
HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
Under that key, you should see a value name Progid. If IE is set to default, you should see IE.HTTP in it. I only tested it on IE9, but I can't imagine there's a difference in older versions of IE.
http://img863.imageshack.us/img863/7930/unlednnr.png
Re: check the default browser
Quote:
HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
hello,i cannot see "Associations" under Shell folder..its BagMRU and Bags folders under a shell folder.
Re: check the default browser
Quote:
Originally Posted by
[gja]
hello,i cannot see "Associations" under Shell folder..its BagMRU and Bags folders under a shell folder.
What OS are you using?
Also, you can use ProcMon to latch onto the iexpore.exe process and see what key it is writing to when it sets the default.
Instead of just taking our suggestions and saying, "it doesn't work" you need to do some leg work on your own.
Re: check the default browser
The following additions to My.Computer should assist (not tested under Windows 7)
InternetExplorerInstalled()
Determines if Internet Explorer is installed
InternetExplorerRunCommand()
Returns the run command for Internet Explorer
InternetExplorerExecutable()
Path and file name for MS-Internet Explorer
DefaultWebBrowser
Get the default web browser
Example
Code:
Console.WriteLine("Default browser [{0}]", My.Computer.DefaultWebBrowser)
If My.Computer.InternetExplorerInstalled Then
Console.WriteLine("IE executable [{0}]", My.Computer.InternetExplorerExecutable)
Console.WriteLine("Run command [{0}]", My.Computer.InternetExplorerRunCommand(False))
Else
Console.WriteLine("Microsoft Internet Explorer not installed")
End If
Output for my computer
Code:
Default browser ["C:\Program Files\Internet Explorer\iexplore.exe"]
IE executable [C:\Program Files\Internet Explorer\IEXPLORE.EXE]
[C:\Program Files\Internet Explorer\iexplore.exe ]
["C:\Program Files\Internet Explorer\iexplore.exe" %1]
Add the attached file to your project
Re: check the default browser
Hello kevin,thank you for your reply.
i used your class like this..
Code:
Try
If My.Computer.InternetExplorerInstalled Then
System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
Else
MessageBox.Show("Microsoft Internet Explorer not installed")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
do you have any advice, if internet explorer is already opened it will not create new instance of it,rather, it will add new tab on existing IE instance?..
Re: check the default browser
Quote:
Originally Posted by
[gja]
Hello kevin,thank you for your reply.
i used your class like this..
Code:
Try
If My.Computer.InternetExplorerInstalled Then
System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
Else
MessageBox.Show("Microsoft Internet Explorer not installed")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
do you have any advice, if internet explorer is already opened it will not create new instance of it,rather, it will add new tab on existing IE instance?..
See comments within the code below.
Code:
If My.Computer.InternetExplorerInstalled Then
If My.Computer.IsInternetExplorerRunning Then
' starting a page should open in the current instance of IE
Else
' new instance of IE will be started
End If
Else
MessageBox.Show("Microsoft Internet Explorer not installed")
End If
Place the following code in the code module I uploaded
Code:
Public Function IsInternetExplorerRunning() As Boolean
Dim query = (From p In System.Diagnostics.Process.GetProcesses() _
Where p.ProcessName = "iexplore").FirstOrDefault
If query IsNot Nothing Then
Return True
Else
Return False
End If
End Function
Re: check the default browser
Hi kevin.
this is what i have now..
Code:
Try
If My.Computer.InternetExplorerInstalled Then
If My.Computer.IsInternetExplorerRunning Then
' starting a page should open in the current instance of IE
System.Diagnostics.Process.Start(TextBox1.Text.Trim)
Else
' new instance of IE will be started
System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
End If
Else
MessageBox.Show("Microsoft Internet Explorer not installed")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
i dont know how to open another site in a new tab...highlighted text above work only if IE is my default browser but my default browser is FF...
Re: check the default browser
Quote:
Originally Posted by
[gja]
Hi kevin.
this is what i have now..
Code:
Try
If My.Computer.InternetExplorerInstalled Then
If My.Computer.IsInternetExplorerRunning Then
' starting a page should open in the current instance of IE
System.Diagnostics.Process.Start(TextBox1.Text.Trim)
Else
' new instance of IE will be started
System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
End If
Else
MessageBox.Show("Microsoft Internet Explorer not installed")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
i dont know how to open another site in a new tab...highlighted text above work only if IE is my default browser but my default browser is FF...
Since I do not have FF I do not have an answer for you.
Re: check the default browser
Hi. I'm usually a new member here. I know there is a way to get if Firefox is your default browser or other browsers..
Its not http for getting the default browser. but it's the ".htm" extension you should check.
How did I find out?
I've tested changing "FirefoxHTML" into another string that is not for firefox then I started running firefox.
When it opens, it says that firefox is not your default browser.
So here is the code that I wrote:
Code:
Public Function GetDefaultBrowser() As String
Dim GetLink As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\.htm", "", "")
'Gets the default value of the .htm extension for locating the default browser's parameter
Dim Result As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" + GetLink + "\shell\open\command", "", "")
'Gets the shell command of the default browser to be returned.
Return Result.ToString
End Function
So if your default browser is firefox, then it will appear the code below
Code:
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1"
If you want to browse something, then just replace "%1" to the web you like. :D
Example:
Code:
Dim WebLocation As String = GetDefaultBrowser.Replace("%1", "vbforums.com")
Shell(WebLocation)
'Replace vbforums.com to any location in the web to be launched by the default browser.
I hope this helped you [gja].