Jump to content

Advice on best way to open/run a url in the default browser


billmez
 Share

Recommended Posts

Hi all,

Is the following code the best way to handle opening a URL in the user's default browser, or does anyone have a more sure way. The reg value here comes from XP pro, and I'm not sure if it applys to other OSes, or if the %1 parameter would apply to other browser types.

$regVal = RegRead("HKEY_CLASSES_ROOT\InternetShortcut\shell\open\command", "")

$regVal = StringReplace($regVal, "%1", "http://www.wpde.com/")

Run($regVal)

Thanks for the input,

billmez

Link to comment
Share on other sites

umm what about

Run(@comspec & " /c start www.wpde.com",@scriptdir, @SW_HIDE)

--maybe?

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

umm what about

Run(@comspec & " /c start www.wpde.com",@scriptdir, @SW_HIDE)

--maybe?

~cdkid

I tried that also and it too worked. I question whether opening a hidden command shell is a better way to handle it than reading the reg key and running the default browser directly. That's why I am asking for advice here.

I would appreciate your thoughts on the +/- or both ways.

Thanks,

billmez

Link to comment
Share on other sites

personally, i prefer using a hidden cmd window cuz that's surefire... i dont know if all OSes have that reg key, so that's just the way i'd go. seems more reliable to me

~cdkid has spoken :o

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Moderators

I use the one in my signature 99% of the time with 2 back ups in case it fails.

If the url string has '%' in it I use:

Local $u_URL_LINK = 'www.yourlink.com/ALPHATEST/return=http%3a%2f%2fyourreturnurl%2ecom'
    Local $OpenUrl = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\https\shell\open\command", "")
    Local $UrlSplit = StringSplit($OpenUrl, '%')
    If IsArray($UrlSplit) And UBound($UrlSplit) - 1 = 2 Then 
        Local $SendUrl = $UrlSplit[1] & $u_URL_LINK & StringTrimLeft($UrlSplit[2], 1)
        Run($SendUrl)
    EndIf

If it does not have a '%' in the string , and my signature DLLCall one has failed, I use:

Run(@ComSpec & " /c Start " & $u_URL_LINK, "", @SW_HIDE)

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

I use the one in my signature 99% of the time with 2 back ups in case it fails.

If the url string has '%' in it I use:

Local $u_URL_LINK = 'www.yourlink.com/ALPHATEST/return=http%3a%2f%2fyourreturnurl%2ecom'
    Local $OpenUrl = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\https\shell\open\command", "")
    Local $UrlSplit = StringSplit($OpenUrl, '%')
    If IsArray($UrlSplit) And UBound($UrlSplit) - 1 = 2 Then 
        Local $SendUrl = $UrlSplit[1] & $u_URL_LINK & StringTrimLeft($UrlSplit[2], 1)
        Run($SendUrl)
    EndIf

If it does not have a '%' in the string , and my signature DLLCall one has failed, I use:

Run(@ComSpec & " /c Start " & $u_URL_LINK, "", @SW_HIDE)
Thanks for the response

What are the benefits of using the dll call method over the regread version, and what OSes/browsers does it fail on?

Also, am I missing something or isn't this just an empty string? StringTrimLeft($UrlSplit[2], 1) And if it is,why are you using it there.

billmez

Link to comment
Share on other sites

$url="http://www.autoitscript.com"
run("RunDLL32.EXE url.dll,FileProtocolHandler "&$url)

Steve

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

  • Recently Browsing   0 members

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