Author: FiberOPtics -- mirc.fiberoptics@gmail.com
Purpose: Create, modify, or return information about Windows Shortcuts.
The shortcuts can be either .lnk or .url files.
Usage:
This snippet can be used in two ways:
The Description property contains a string value describing a shortcut.
Requirements: mIRC 5.9
Examples: Note that the examples are most likely not going to work on your system, as I don't know what folder you have installed mIRC in, nor can I predict what the exact path to your userprofile folder is.
/shortcut c:\mirc.lnk, c:\program files\mirc\mirc.exe, c:\program files\mirc\mirc.exe, 1, ctrl+m, mIRC
/shortcut d:\documents and settings\FO\favorites\my mirc sites\mirc.url, www.mirc.com
$shortcut(d:\shortcuts\foobar.lnk, targetpath)
Note that my $specialfolder snippet can be quite handy to use along with //shortcut, as you could write a shortcut to the StartMenu, Startup, Favorites, Sendto, Desktop...
Example of writing a shortcut to your desktop for a hypothetical full script:
(we use double // from the commandline to let the identifiers $specialfolder, $mircexe and $+ evaluate)
//shortcut $specialfolder(desktop) $+ \myscript.lnk, $mircexe , 2 $mircexe ,,alt+e
will create a shortcut to mirc.exe with the old icon (index 2), and shortcut alt+e. This means if you are on the desktop, and you press alt+e, it will execute the shortcut.
//shortcut $specialfolder(favorites) $+ \Microshaft.url, www.microsoft.com
will create the URL shortcut "Microshaft" in the Favorites folder, which navigates to microsoft.com, when executed.
Notes:
alias shortcut {
var %e = !echo $color(info) -a * Shortcut:
if ($isid) {
if (!$isfile($1)) { %e Shortcut doesn't exist. | return }
var %props = Targetpath Windowstyle Hotkey Iconlocation Description Workingdirectory
if (!$istok(%props,$2,32)) {
tokenize 32 %props
%e Incorrect property. Possible: | echo -a $* | return
}
}
else {
var %a, %b = $regsub($1-,/\s*\54\s*/g,$chr(44),%a) $regsub(%a,/(?<=\54)(?=\54)/g,$lf,%a)
tokenize 44 %a
}
if (!$regex(ext,$1,/\.(lnk|url)$/)) { %e Incorrect shortcut extension. | return }
if (!$isdir($nofile($1))) { %e Invalid folder path to shortcut. | return }
if ($mkfn($nopath($1)) != $nopath($1)) { %e Name contains invalid characters. | return }
if ($regml(ext,1) == lnk) && (!$isid) && (!$isfile($2) || !$isdir($nofile($2))) {
%e Targetpath does not exist. | return
}
var %objWSH = a $+ $ticks, %objLink = b $+ $ticks
var %tmp = $iif($isid,return,echo -a) COM Error
.comopen %objWSH wscript.shell
if ($comerr) %tmp
.comclose %objWSH $com(%objWSH,createshortcut,1,bstr*,$1,dispatch* %objLink)
if (!$com(%objLink)) %tmp
if ($isid) {
%tmp = $com(%objLink,$2,2)
%tmp = $com(%objLink).result
.comclose %objLink
return %tmp
}
if (!$com(%objLink,targetpath,4,bstr*,$2)) && ($show) %e Could not set targetpath.
if ($regml(ext,1) == lnk) {
if ($regex(icon,$3,/^(\d|)\s*(.+)/)) {
var %loc = $regml(icon,2)
if ($isfile(%loc)) && ($isdir($nofile(%loc))) {
if (!$com(%objLink,iconlocation,4,bstr*,%loc $chr(44) $gettok($regml(icon,1) 0,1,32))) && ($show) {
%e Could not set iconlocation/index.
}
}
}
if ($istok(1 3 7,$4,32)) && (!$com(%objLink,windowstyle,4,uint,$4)) && ($show) {
%e Could not set windowstyle.
}
if ($regex(hotkey,$5,/^(?:(?:alt|ctrl|shift|ext)\+)+(?:[a-z\d]|f\d|f1[0-2])$/i)) {
if (!$com(%objLink,hotkey,4,bstr*,$5)) && ($show) %e Could not set hotkey.
}
if ($6 != $lf) && (!$com(%objLink,description,4,bstr*,$6)) && ($show) {
%e Could not set description.
}
%tmp = $com(%objLink,workingdirectory,4,bstr*,$nofile($2))
}
if (!$com(%objLink,save,1)) %e Error creating shortcut.
.comclose %objLink
}