Jump to content

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


Recommended Posts

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- #
Link to comment
Share on other sites

  • Moderators

Have you looked at the ShellExecute API?

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.

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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)

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.

Link to comment
Share on other sites

  • 3 weeks later...

This is what I use.

Run("RunDLL32.EXE url.dll,FileProtocolHandler " &  $sURL)
Edited by eltorro
Link to comment
Share on other sites

  • Moderators

Try this

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

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

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.

Link to comment
Share on other sites

  • 10 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...