Results 1 to 5 of 5

Thread: Browser...

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Question Browser...

    Hi,

    How would I be able to detect the browser (default) on the computer and open it with a specific URL ?
    I don't want to shell it unless I have to.

    Regards

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    but....

    but what you just said constitutes shelling it.

  3. #3

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Uhhh

    well yeeeeeeees, but I wanted an object I could do things with like print or whatever...

    Not that it matters much, haven't written the export routine yet.

    Regards

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    It seems to me that just using Shell would be a heck of lot easier, but if you want to know how to find the default browser...
    VB Code:
    1. Private Declare Function FindExecutable Lib "shell32" _
    2.    Alias "FindExecutableA" _
    3.   (ByVal lpFile As String, _
    4.    ByVal lpDirectory As String, _
    5.    ByVal sResult As String) As Long
    6.  
    7. Private Declare Function GetTempPath Lib "kernel32" _
    8.    Alias "GetTempPathA" _
    9.   (ByVal nSize As Long, _
    10.    ByVal lpBuffer As String) As Long
    11.  
    12. Private Const MAX_PATH As Long = 260
    13. Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31
    14. Private Const ERROR_FILE_NOT_FOUND As Long = 2
    15. Private Const ERROR_PATH_NOT_FOUND As Long = 3
    16. Private Const ERROR_FILE_SUCCESS As Long = 32 'my constant
    17. Private Const ERROR_BAD_FORMAT As Long = 11
    18.  
    19.  
    20. Private Sub Command1_Click()
    21.  
    22.    Dim success As Long
    23.    Dim sBrowser As String
    24.    
    25.   'success is passed and filled in the routine
    26.    sBrowser = GetBrowserName(success)
    27.    
    28.   'possible return values from the call
    29.   'returned in success
    30.    Select Case success
    31.      
    32.      'the call succeeded
    33.       Case Is >= ERROR_FILE_SUCCESS
    34.      
    35.          MsgBox sBrowser
    36.          Exit Sub
    37.          
    38.      'other possible return values
    39.       Case ERROR_FILE_NO_ASSOCIATION
    40.       Case ERROR_FILE_NOT_FOUND
    41.       Case ERROR_PATH_NOT_FOUND
    42.       Case ERROR_BAD_FORMAT
    43.       Case Else:
    44.    End Select
    45.      
    46.    
    47.   'if this far the call failed
    48.    MsgBox "No dice!"
    49.    
    50. End Sub
    51.  
    52.  
    53. Private Function GetBrowserName(dwFlagReturned As Long) As String
    54.  
    55.    Dim hFile As Long
    56.    Dim sResult As String
    57.    Dim sTempFolder As String
    58.        
    59.   'get the user's temp folder
    60.    sTempFolder = GetTempDir()
    61.    
    62.   'create a dummy html file in the temp dir
    63.    hFile = FreeFile
    64.       Open sTempFolder & "dummy.html" For Output As #hFile
    65.    Close #hFile
    66.  
    67.   'get the file path & name associated with the file
    68.    sResult = Space$(MAX_PATH)
    69.    dwFlagReturned = FindExecutable("dummy.html", sTempFolder, sResult)
    70.  
    71.   'clean up
    72.    Kill sTempFolder & "dummy.html"
    73.    
    74.   'return result
    75.    GetBrowserName = TrimNull(sResult)
    76.    
    77. End Function
    78.  
    79.  
    80. Private Function TrimNull(item As String)
    81.  
    82.     Dim pos As Integer
    83.    
    84.     pos = InStr(item, Chr$(0))
    85.    
    86.     If pos Then
    87.           TrimNull = Left$(item, pos - 1)
    88.     Else: TrimNull = item
    89.     End If
    90.  
    91. End Function
    92.  
    93.  
    94. Public Function GetTempDir() As String
    95.  
    96.     Dim nSize As Long
    97.     Dim tmp As String
    98.    
    99.     tmp = Space$(256)
    100.     nSize = Len(tmp)
    101.     Call GetTempPath(nSize, tmp)
    102.    
    103.     GetTempDir = TrimNull(tmp)
    104.    
    105. End Function

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    vince... after seeing that. I'll bet u just changed yer mind LOL

    (hack is god! hack is god!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width