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:
  1. Private Function getDefaultBrowser() As String
  2.     Dim retVal As String = String.Empty
  3.     Using baseKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Clients\StartmenuInternet")
  4.          Dim baseName As String = baseKey.GetValue("").ToString
  5.          Dim subKey As String = "SOFTWARE\" & IIf(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") = "AMD64", "Wow6432Node\", "") & "Clients\StartMenuInternet\" & baseName
  6.          Using browserKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey(subKey)
  7.               retVal = browserKey.GetValue("").ToString
  8.          End Using
  9.      End Using
  10.      Return retVal
  11. 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:
  1. MessageBox.Show(String.Concat("Your default browser is: ", getDefaultBrowser(), "."), "Your default browser")

Cheers,
Jason.