Jump to content

Create URL Shortcuts


GEOSoft
 Share

Recommended Posts

Just for creating shortcuts without having to right click the desktop (or other folder) and go through that process. Similar To FileCreateShortcut()

;
Func _URLCreateShortcut($sUrl, $sName, $sFldr = @DesktopDir) 
     $sFldr = StringRegExpReplace($sFldr, "\\+\z", "") & "\" 
     If NOT FileExists($sFldr) Then Return SetError(1) 
     $sName = StringReplace($sName, ".url", "") & ".url" 
     Local $Ini = $sFldr & $sName, $iSec = "InternetShortcut" 
     $sUrl = StringRegExpReplace($sUrl, "^.*?:/+", "") 
     IniWrite($Ini, $iSec, "URL", $sURL) 
     IniWrite($Ini, $iSec, "IDList", "") 
     IniWrite($Ini, $iSec, "IconFile", "") 
     IniWrite($Ini, $iSec, "IconIndex", "") 
EndFunc
;

Call it this way.

;
_URLCreateShortcut("www.autoitscript.com/forum/index.php?act=idx", "AutoIt Forums")
;

Notes:

(1) You do not have to include the http:// but you can if you want.

(2) If the site uses a favicon.ico file then it may or may not appear when the shortcut is created. Sometimes it will not appear until after the shortcut has been used once.

EDIT: I should have added that this has only been tested on IE.

EDIT 2: Thanks to Saunders suggestion I have modified the way $sURL is handled. There were several situations wher the old version would have failed. For example ftp links or links to https://

EDIT 3: Thanks to Smoke_N it's now using RegEx. As a side note, "DO NOT" comment out the blank ini fields. They are there for a reason.

Have fun.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hmm, it's not very likely, but this line could cause problems:

$sUrl = "http://" & StringReplace($sUrl, "http://","")

If you want to create a shortcut to a page that has a query string that has http in it. Like: "http://mywebpage.com/somescript.php?url=http://anothersite.com"

By all rights, that part should be URL encoded and so wouldn't look like "http://" (should actually look like "http%3A//"), but I could see someone goofing it up. Perhaps use a regular expression to ensure the http is at the beginning of the string?

Link to comment
Share on other sites

Hmm, it's not very likely, but this line could cause problems:

$sUrl = "http://" & StringReplace($sUrl, "http://","")

If you want to create a shortcut to a page that has a query string that has http in it. Like: "http://mywebpage.com/somescript.php?url=http://anothersite.com"

By all rights, that part should be URL encoded and so wouldn't look like "http://" (should actually look like "http%3A//"), but I could see someone goofing it up. Perhaps use a regular expression to ensure the http is at the beginning of the string?

Actually now that you bring it up, it might cause an issue. I can fix that easy enough by doing a check first.

Thanks.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...