Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have this code to get the default browser and do some thing like open url etc ... then close it again
i found this code but it give me alot of error

Private Function getDefaultBrowser() As String
    Dim browser As String = String.Empty
    Dim key As RegistryKey = Nothing
    Try
        key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)

        'trim off quotes
        browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
        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


and this for looping
VB
Dim browser As String
browser = getDefaultBrowser()
For Each p As Process In Process.GetProcesses        
    If p.ProcessName = browser Then
        p.Kill()
        Exit For
    End If
Next
Posted
Comments
Patrice T 26-Jan-16 19:05pm    
"it give me a lot of error" is not a problem description

1 solution

I dont see why you need to 'get' the default browser - your system knows what the default browser is - so you only need to do

CreateObject("WScript.Shell").Run "www.codeproject.com"


to open CP with the default browser. If you want to open a URL in a specific browser, then it becomes a little more difficult - but you can google for code to do that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900