>1. I want to shell the default browser from VB code with an url I specify.
>
>
>2. Along the same lines: I want to open the default browser with a Http
>Post.
You can determine the path and EXE name of the default browser using the
"FindExecutable" API and the UDF "GetAssociatedExeFile". Also, have a look
at the "ShellExecuteEx" API; you have much greater control over how
shelling to an external application occurs.
' ----- Begin code -----------------
' In the general declarations section:
Private Declare Function FindExecutable _
Lib "shell32.dll" Alias "FindExecutableA" _
( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String _
) As Long
Private Sub Form_Load()
Private sTxt as String
sTxt = GetAssociatedExeFile("HTM")
If sTxt="" Then
sTxt = "No program is associated with HTM files"
Else
sTxt = "HTM Files are associated with " & sTxt
End If
MsgBox sTxt
End Sub
' Then somewhere in your form:
Private Function GetAssociatedExeFile( _
cDummyFileExtension As String) As String
Dim sFileName As String
Dim sAssociatedExec As String * 255
Dim lRetVal As Long
Dim nFileHandle As Integer
Dim sTemp As String
sAssociatedExec = Space(255)
sFileName = App.Path & _
IIf(Right$(App.Path, 1) <> "\", "\", "") & _
"temp." & cDummyFileExtension
If Dir(sFileName) <> "" Then Kill sFileName
nFileHandle = FreeFile() ' Get unused file number
Open sFileName For Output As #nFileHandle ' Create temporary file
Print #nFileHandle, "dummy text" ' Output some text
Close #nFileHandle ' Close file
' Then find the application associated with it.
lRetVal = FindExecutable(sFileName, sTemp, sAssociatedExec)
' If an application return the name
If lRetVal <= 32 Or IsEmpty(sAssociatedExec) Then ' Error
GetAssociatedExeFile = ""
Else
GetAssociatedExeFile = Trim$(sAssociatedExec)
End If
Kill sFileName ' delete temp file
End Function
' ----- End Code -----------------
Regards,
-Toby