Advertisement
3DotDev

Récupérer le chemin du navigateur Internet par défaut

Jun 4th, 2017
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.81 KB | None | 0 0
  1. '########################################################
  2. ' Credits 3DotDev from http://3dotdevcoder.blogspot.fr/
  3. '########################################################
  4.  
  5. Public Shared Function GetDefaultBrowserPath() As String
  6.         Dim defaultBrowserPath As String = String.Empty
  7.         Dim regkey As RegistryKey = Nothing
  8.         Try
  9.             regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\shell\Associations\UrlAssociations\http\UserChoice", False)
  10.             If regkey IsNot Nothing Then
  11.                 Dim ProgId = regkey.GetValue("Progid").ToString()
  12.                 regkey = Registry.ClassesRoot.OpenSubKey(ProgId & "\Shell\open\command", False)
  13.                 defaultBrowserPath = If(Not regkey Is Nothing,
  14.                     regkey.GetValue("").ToString(),
  15.                     Registry.ClassesRoot.OpenSubKey("HTTP\Shell\open\command", False).GetValue("").ToString())
  16.             Else
  17.                 defaultBrowserPath = Registry.ClassesRoot.OpenSubKey("HTTP\Shell\open\command", False).GetValue("").ToString()
  18.             End If
  19.         Catch ex As Exception
  20.  
  21.         Finally
  22.             If Not regkey Is Nothing Then regkey.Close()
  23.         End Try
  24.         Return CleanupPath(defaultBrowserPath)
  25.     End Function
  26.  
  27.     Private Shared Function CleanupPath(path$) As String
  28.         path = path.ToLower().Replace("""", "")
  29.         If Not path.EndsWith(".exe") Then
  30.             path = path.Substring(0, path.LastIndexOf(".exe", StringComparison.Ordinal) + ".exe".Length)
  31.         End If
  32.         Return path
  33.     End Function
  34.  
  35. '############################### Vous pouvez exécuter une URL dans votre navigateur par défaut ###########################
  36.     Public Shared sub ExecUrl()
  37.         Process.Start(GetDefaultBrowserPath,"http://3dotdevcoder.blogspot.fr")
  38.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement