Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Get default browser path

I did some research around the internet on how to get default browser's path.
I found only long codes, sometimes needing whole modules and APIs; so I decided to write my own method, just few lines of code and no APIs needed...

Here it's code.
Code
Function DefaultBrowser() As String

Dim regshell As Object
Set regshell = CreateObject("Wscript.Shell")

' Reads the registry value where is stored the default application to use with HTTP
DefaultBrowser = regshell.regread("HKEY_CLASSES_ROOT\HTTP\shell\open\command\")

' Removes shell parameters after the actual path, preserving only path included in double       ' quotes
DefaultBrowser = Left(DefaultBrowser, InStr(1, DefaultBrowser, ".exe", vbTextCompare) + 4)

' Removes double quotes (")
DefaultBrowser = Replace(DefaultBrowser, Chr(34), vbNullString)

End Function
Quote: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


There you can get the default browser. Then you can loop through the running process and kill the browser.

Quote: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


http://stackoverflow.com/questions/18995...-in-vb-net
Assert failure(PID 10704 [0x000029d0], Thread: 10960 [0x2ad0]): pBuffer != NULL


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by MatriculateMar 5, 2016 07:03 AM 6 235 Mar 5, 2016 07:03 AM
Last Post: Ninja
[C#] by frappppSep 7, 2015 02:59 PM 2 332 Sep 7, 2015 02:59 PM
Last Post: camelCase
[.NET] by ShikatanaiJun 17, 2015 07:21 PM 12 565 Jun 17, 2015 07:21 PM
Last Post: Shikatanai