469,323 Members | 1,567 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

How to get the path to the users default browser?

I need to be able to get the path to the users default browser from within my application.

I am in a situation where I can't easily use System.Diagnostics.Process.Start to start
their browser with the URL I want and I must resort to using "Shell". Of course, shell
wants to know where the browser is and now you can see my dilemma!

Thanks in advance...

Nov 21 '05 #1
6 11351
You will need to query this registry path:

HKEY_CLASSES_ROOT\http\shell\open\command

The default key contains the path
Nov 21 '05 #2
Sorry, but forgot to add this one too:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\http\shell\ope n\command
Nov 21 '05 #3
On Mon, 14 Feb 2005 14:35:48 -0800, "Darious Snell" <nu**@sdlkfweu.org> wrote:

I need to be able to get the path to the users default browser from within my application.

I am in a situation where I can't easily use System.Diagnostics.Process.Start to start
their browser with the URL I want and I must resort to using "Shell". Of course, shell
wants to know where the browser is and now you can see my dilemma!

Give the following a try:

Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As
String, _
ByVal lpDirectory As
String, _
ByVal lpResult As
System.Text.StringBuilder) As Int32

Function DefaultBrowserPath() As String

Dim DummyFile As String
Dim FileDir As String

Dim FilePath As New System.Text.StringBuilder(255)
DummyFile = "e:\My Documents\dummy.htm"

If FindExecutable(DummyFile, FileDir, FilePath) > 32 Then
DefaultBrowserPath = FilePath.ToString
End If

End Function
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #4
Just a quick note...

An example of what can be stored in that key...

C:\PROGRA~1\MOZILL~1\FIREFOX.EXE -url "%1"

There needs to be a little string manipulation before using
this in a "shell" command. I came up with
Dim MyString As String
Dim MySplitStrings() As String
Dim ExeString As String
Dim BrowserRegKey As String = "SOFTWARE\Classes\http\shell\open\command"
Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey(BrowserRegKey, False)
MyString += CType(rk.GetValue(""), String)
MySplitStrings = MyString.Split(" ")
ExeString = MyStrings(0).ToString

This works with IE and Firefox. Probably most anything else as well.
I am sure there are more elegant ways to do this. But, this works for
the moment.

Thanks
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
You will need to query this registry path:

HKEY_CLASSES_ROOT\http\shell\open\command

The default key contains the path

Nov 21 '05 #5
In article <11*************@corp.supernews.com>, Darious Snell wrote:
I need to be able to get the path to the users default browser from within my application.

I am in a situation where I can't easily use System.Diagnostics.Process.Start to start
their browser with the URL I want and I must resort to using "Shell". Of course, shell
wants to know where the browser is and now you can see my dilemma!

Thanks in advance...


I'm a little confused... If you have a URL, you don't even need to know
their default browser using System.Diagnostics.Process. You just set
the filename property of the startinfo structure to the URL and make
sure useshellexectue is true. The system will start the default browser
automatically.

Dim browser As New Process ()
browser.StartInfo.FileName = "http://www.microsoft.com"
browser.StartInfo.UseShellExecute = True
browser.Start ()
--
Tom Shelton [MVP]
Nov 21 '05 #6
The reason I am having difficulty using .start ----

"The requested section is not present in the activation context"

This shows up due to threading model issues with the architecture.
I couldn't resolve the threading issues so I ended up using shell.
I tried using STAThread/MTAThread etc but I couldn't clear the issue.
So, "shell" produces the desired outcome. But, you are right, my first
choice was to go with the method you describe below.
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
In article <11*************@corp.supernews.com>, Darious Snell wrote:
I need to be able to get the path to the users default browser from within my application.
I am in a situation where I can't easily use System.Diagnostics.Process.Start to start their browser with the URL I want and I must resort to using "Shell". Of course, shell wants to know where the browser is and now you can see my dilemma!

Thanks in advance...


I'm a little confused... If you have a URL, you don't even need to know
their default browser using System.Diagnostics.Process. You just set
the filename property of the startinfo structure to the URL and make
sure useshellexectue is true. The system will start the default browser
automatically.

Dim browser As New Process ()
browser.StartInfo.FileName = "http://www.microsoft.com"
browser.StartInfo.UseShellExecute = True
browser.Start ()
--
Tom Shelton [MVP]

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jerrygarciuh | last post: by
4 posts views Thread by Hal Vaughan | last post: by
10 posts views Thread by Don Munroe | last post: by
4 posts views Thread by Cubaman | last post: by
11 posts views Thread by cybervigilante | last post: by
9 posts views Thread by Jonathan Wood | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.