as ordinary links created using COM do, only these are simple text files, so the coding is very
straightforward and simple.
The procedure creates non-existant folders listed in the path to the shortcut, and you can
specify an icon library/index for the shortcut as well.
The demo creates a shortcut to Notepad on your desktop (#CSIDL_DESKTOPDIRECTORY) with an icon.
Code: Select all
;-PB4, 20061204, utopiomania
;creates internet shortcuts to a file or web resource
;creates folders on the fly if neccessary
procedure createShortcut(file, res.s, url.s, icon.s, index)
;creates internet shortcuts. res: linked to, url: shortcut path
;icon: the path of the icon library file, .ico, .dll or .exe
;index: the icon index within the icon library file
dq.s = chr(34)
if file
;links to a file
res = "file://" + res
else
;links to a web resource
res = "http://" + res
endIf
if lcase(right(url, 4)) <> ".url"
url = url + ".url"
endIf
;try to create folders from the top down
for i = 1 to len(url)
if mid(url, i, 1) = "\"
;create folder:
createDirectory(left(url, i))
endIf
next
if createFile(0, url)
writeStringN(0, "[InternetShortcut]")
writeStringN(0, "URL = " + dq + res + dq)
if file
if len(icon)
writeStringN(0, "IconFile = " + dq + icon + dq)
writeStringN(0, "IconIndex = " + dq + str(index) + dq)
endIf
endIf
closeFile(0)
procedureReturn 1
endIf
procedureReturn 0
endProcedure
procedure.s getSpecialFolder(id)
protected path.s, *ItemId.ITEMIDLIST
*itemId = #Null
if SHGetSpecialFolderLocation_(0, id, @*ItemId) = #NOERROR
path = space(#MAX_PATH)
if SHGetPathFromIDList_(*itemId, @path)
if right(path, 1) <> "\"
path + "\"
endIf
procedureReturn path
endIf
endIf
procedureReturn ""
endProcedure
res.s = getSpecialFolder($24) + "notepad.exe"
url.s = getSpecialFolder($10) + "SHORTCUT"
;create folders:
;url.s = getSpecialFolder($10) + "FOLDER\SHORTCUT"
createShortcut(1, res, url, res, 0)
messageRequester("!", "A SHORTCUT to Notepad was created on your desktop", #PB_MessageRequester_Ok)
end