Sign in to follow this  
Followers 0
AzKay

VB6 - Anyone know how to open a url in the default browser?

12 posts in this topic

Well, i know i may not get many replys, because most of you probly dont know visual basic, but some might, thats why im asking this.

Ok, I have a button, called "Forum" when i click the button, i want it to open up the default browser, and go to the url.

How can I do this?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites



Have you looked at the ShellExecute API?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Have you looked at the ShellExecute API?

no, but i will, thanks

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well when you tell it to open a window it will automaticly use the default browser if you code it in vb the action for the button would look like this:

function opensite(){
var site="http://www.google.com"
winopen=window.open(site)
}

If I understand you correctly just attach this as the button actiaon "opensite()" use that except the google.com part change that and use the mouse click function

I am not sure exactly how it is you are trying to go about this?

That was "vbscript" is that what you ment or did you mean actual "Visual Basic"

Are you trying to write this using autoit code? I have nvr tried using outside programing in autoit so I have nvr looked up autoits functionality with other scripts so.

Edited by Sublime

Share this post


Link to post
Share on other sites

In AutoIt...

; open a URL in the user's "default browser"...
func VisitURL($url)
    $browser_str = RegRead("HKEY_CLASSES_ROOT\HTTP\shell\open\command", "")
    $browser_str = StringReplace($browser_str, '"%1"', $url)
    run($browser_str, "", @SW_SHOW)
endfunc

I don't know about VB, but I know that often opening a URL means getting IE rather than your default browser (*grrr* AutoIt!). The crucial step is checking in the registry first, which I'm sure you can figure out how to do in VB.

-mu

Share this post


Link to post
Share on other sites

I can't speak to VB6, but I know I've grappled with this problem in AutoIt before. Suggestions ranged from parsing the registry to find out what the user's preferred browser is, however I recently came across some rediculously easy code.

_RunDos("start http://www.google.com")

_RunDos is a UDF, basically it runs a DOS command in a hidden window. You can do this manually if you just go to DOS and type 'start (url)'. I'm pretty familiar with DOS and never knew about this.

I use firefox. When I ran this command it immediately opened firefox and went to that URL. Pretty nifty.

Again, doesn't answer your question about VB6, but seeing as how that's a feature of Windows/DOS and not AutoIt/VB6, you should be able to make it work in VB by issuing that command to the DOS prompt.

Good luck.

Share this post


Link to post
Share on other sites

Nice!

So, even without a UDF, it's simply...

Run(@ComSpec & " /c " & "start http://www.google.com", "", @SW_HIDE)

Yup!

"start" is the key. Noted. Cheers!

I guess it would be easy enough to send this command in VB.

-mu

Share this post


Link to post
Share on other sites

This is kind of what I was talking about:

Local $Url = 'http://www.google.com'
DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", 'open', "string", $Url, "string", '', "string", @ScriptDir, "long", @SW_SHOWNORMAL)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This is what I use.

Run("RunDLL32.EXE url.dll,FileProtocolHandler " &  $sURL)
Edited by eltorro

Share this post


Link to post
Share on other sites

Try this

run("C:\Program Files\Internet Explorer\iexplore.exe www.compaq.com")


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

Try this

run("C:\Program Files\Internet Explorer\iexplore.exe www.compaq.com")

FireFox is my default browser. And C:\ may not be mapped.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This looks goooooood

 

Public Sub OpenDefaultBrowser(weburl As String)
Dim r As Long
   r = ShellExecute(0, "open", weburl, 0, 0, 1)

End Sub

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0