|
-
Apr 20th, 2011, 07:13 AM
#1
Thread Starter
Fanatic Member
Obtain user's default browser.
Been a while since I posted anything here, thought I'd share a little snippet I wrote up the other day for someone. Just a really simple way to determine the user's default web browser (Chrome, Firefox...etc)
vb.net Code:
Private Function getDefaultBrowser() As String Dim retVal As String = String.Empty Using baseKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Clients\StartmenuInternet") Dim baseName As String = baseKey.GetValue("").ToString Dim subKey As String = "SOFTWARE\" & IIf(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") = "AMD64", "Wow6432Node\", "") & "Clients\StartMenuInternet\" & baseName Using browserKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey(subKey) retVal = browserKey.GetValue("").ToString End Using End Using Return retVal End Function
A basic walkthrough of the function for those interested:
Firstly, the function opens the registry key @ HKEY_CURRENT_USER\Sofware\Clients\StartmenuInternet
The default value at this registry key is the executable name of your default browser (IEXPLORE9.EXE, FIREFOX.EXE, Chrome.exe...etc), these names aren't overly helpful as it's not the actual browser's "name". However, they do help out, so we will store this in the "baseName" variable for later use.
The next step is to build our next registry location. Due to the difference in registry keys on a 32 bit vs 36 bit system the ternary "IIf" operator was used here to apply the "Wow6432Node" if necessary (64 bit systems). The StartMenuInternet key contains multiple sub keys, one for each browser you have installed, coincidentally the subkey names correspond to the value stored in baseName, so we use that variable to open the "default browser's" folder.
This is the moneymaker, the default value at this key is the actual name of the browser, so we just assign retVal the default key value and call it quits.
Return retVal <- self explanatory, return the value we found.
(Not yet tested on a 32 bit system so if someone finds an error please point it out)
Example of basic use:
vb.net Code:
MessageBox.Show(String.Concat("Your default browser is: ", getDefaultBrowser(), "."), "Your default browser")
Cheers,
Jason.
If I helped you out, please take the time to rate me 
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
|