Discussion:
Launching Browser with a specific URL
(too old to reply)
Ric Deez
2004-01-29 05:25:02 UTC
Permalink
Hi there,

I was wondering if it would be possible to automatically launch a browser
with a specific URL via VB. The idea is that the VB code will run on client
machines listening for requests on a specific port and then launch the
browser when it gets told to. (So this is not for popups in vbscript or
anything like that!!!)

If anyone can help please let us know...

Regards,

Ric
Rod
2004-01-29 06:42:21 UTC
Permalink
Try this...

Declare the following function:

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile
As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long


And this Sub

Private Sub OpenUrl(URL As String)
Dim hBrowse As Long
On Error GoTo OpenURL_Err
hBrowse = ShellExecute(Me.hWnd, "open", URL, "", "", 1)
Exit Sub

OpenURL_Err:
'If for some reason we cant open a browser or email prog then show error
msg
Dim sError As String
If Left$(URL, 4) = "http" Then sError = "An Internet Browser"
If Left$(URL, 4) = "mail" Then sError = "Your Default Email Client"

MsgBox "An Error Has Occured While Trying To Open " + sError +
vbCrLf + vbCrLf + _
"Please Ensure Your Application Is Correctly Installed.", vbCritical
+ vbOKOnly, "Ooops..."

End Sub



And call it from your app like this:

To open a web page....

OpenUrl ("http://www.myDesiredSite.com")

Or to send an email....

OpenUrl ("mailto:***@somewhere.com")

HTH
Post by Ric Deez
Hi there,
I was wondering if it would be possible to automatically launch a browser
with a specific URL via VB. The idea is that the VB code will run on client
machines listening for requests on a specific port and then launch the
browser when it gets told to. (So this is not for popups in vbscript or
anything like that!!!)
If anyone can help please let us know...
Regards,
Ric
Loading...