Tipp 0072 Standard-Browser ermitteln
Autor/Einsender:
Datum:
  Detlev Schubert
27.05.2001
Entwicklungsumgebung:   VB 5
Gerade für das Anzeigen von HTML-Dateien ist es wichtig zu wissen, welcher Browser auf dem jeweiligen System installiert ist, wobei bei diesem Beispiel mittels der API-Funktion FindExecutable auch noch der komplette Pfad des Browsers zurückgeliefert wird.
 
Option Explicit

Private Declare Function FindExecutable Lib "shell32.dll" Alias _
    "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory _
    As String, ByVal lpResult As String) As Long

Private Function StandardBrowser(Browser As String) As String
  Dim sExe As String
  Dim tmpFile As String
  Dim dNr As Integer

  tmpFile = App.Path + IIf(Right$(App.Path, 1) <> "\", "\", "") _
      + "xxx.html"
  dNr = FreeFile
  Open tmpFile For Output As #dNr
  Close #dNr

  sExe = ExePfad(tmpFile)
  Kill tmpFile

  If sExe <> "" Then
    If InStr(LCase$(sExe), "iexplore") > 0 Then
      Browser = "Microsoft Internet Explorer"
    ElseIf InStr(LCase$(sExe), "netscape") > 0 Then
      Browser = "Netscape Communicator"
    ElseIf InStr(LCase$(sExe), "opera") > 0 Then
      Browser = "Opera"
    Else
      Browser = "kein Browser installiert."
    End If
  End If

  StandardBrowser = sExe
End Function

Private Function ExePfad(ByVal Datei As String) As String
  Dim Pfad As String

  Pfad = Space$(256)
  FindExecutable Datei, vbNullString, Pfad

  If Pfad <> "" Then
    Pfad = Left$(Pfad, InStr(Pfad, vbNullChar) - 1)
  End If

  If UCase$(Pfad) = UCase$(Datei) Then Pfad = ""
  ExePfad = Pfad
End Function

Private Sub Command1_Click(Index As Integer)
  Dim Browser As String
  Select Case Index
    Case 1
      Label1(4).Caption = StandardBrowser(Browser)
      Label1(2).Caption = Browser
    Case Else
      Unload Me
      End
  End Select
End Sub
 
Weitere Links zum Thema
Hyperlink folgen
Webbrowser mit vorgegebener URL öffnen

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (2,4 kB) Downloads bisher: [ 1275 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Sonntag, 21. August 2011