Shortcuts

By FiberOPtics on Jan 04, 2006

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:



  1. /shortcut pathtolink, targetpath, [[iconindex] iconlocation], [windowstyle], [hotkey], [description]


    to create or modify a shortcut.



  2. $shortcut(pathtolink, property)


    to return information about an existing shortcut.




    Properties: Targetpath Iconlocation Windowstyle Hotkey Description Workingdirectory




    When creating/modifying a shortcut, the following properties are necessary: pathtolink, targetpath




    Pathtolink



    The full path of where you want to create the link to. Must include the .lnk or .url extension.




    Examples:


    c:\documents and settings\FO\desktop\mirc.lnk


    c:\documents and settings\FO\favorites\my site.url




    Targetpath



    Set the path to the file that the shortcut should link to. This file will be initiated when executing the shortcut.


    Example: c:\program files\mirc\mirc.exe




    [iconindex] iconlocation



    A string that locates the icon which the shortcut should use for representation. The string should contain a fully qualified path.
    An icon index can be specified, which will be associated with the shortcut. If you don't specify an index, the snippet will use 0 as default.




    Examples:


    1,c:\program files\mirc\mirc.exe


    d:\documents\mydoc.doc




    Windowstyle



    1 - Activates and displays a window: if the window is minimized or maximized, the system restores it to its original size and position.




    3 - Activates the window and displays it as a maximized window.




    7 - Minimizes the window and activates the next top-level window.






    Hotkey



    A string representing the key-combination to assign to the shortcut. A hotkey is a combination of keys that starts a shortcut when all associated keys are held down at the same time. Hotkeys can be used to start shortcuts located on your system's desktop and in the Windows Start menu.




    Syntax: [KeyModifier]KeyName




    KeyModifier can be any one of the following: ALT+, CTRL+, SHIFT+, EXT+. Keyname is not case-sensitive: a ... z, 0 ... 9, F1 F12, ...




    Example: ctrl+alt+e






    Description



    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:



    • When creating .url shortcuts, only the targetpath should be specified. This targetpath should be an url, which is the url that the shortcut will navigate to when executed.



    • When creating .lnk shortcuts, only the path to the link, and the targetpath are required. The other properties are optional. However, if you want the link to have an icon, it's best to specify an iconlocation and optional index.



    • When using the $shorctut identifier to retrieve information on a link, the only property that will work on an .url will obviously be targetpath, which will return the url.



    • On .lnk files, it will very often not return all properties. This is not because of the snippet, but simply because the values weren't filled in. A common thing is that the iconlocation property, virtually always only returns the index number (usually 0) and not the path to the iconfile. On shortcuts that you made yourself with the snippet, it will always return the values you've inputted.



    • If you do not wish to fill the values of certain optional properties, then just leave them blank.


      Example:


      /shortcut c:\shortcut to tmp.txt.lnk, d:\docs\tmp.txt, , , ,foobar



    • If you prefix the shortcut command with a dot like //.shortcut, then any error messages, that are the result of a property being unable to set, will not be shown. COM errors, and the error when a shortcut was unable to be created are always shown though.

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
}

Comments

Sign in to comment.
Sasuke   -  Jan 05, 2006

This deserves a ten.. it works and it\'s clean (for all I know)

 Respond  
RoninWarrior   -  Jan 04, 2006

as useuall extreme work! nice job fiber.

 Respond  
RoninWarrior   -  Jan 04, 2006

as useuall extreme work! nice job fiber.

 Respond  
Cross   -  Jan 04, 2006

Long description, Looks very nice.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.