mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2015
Posts: 101
klez Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Sep 2015
Posts: 101
Hi! I don't know so good to work with $com objects, but i need a script (alias) using $com objects that will return the same thing as in the following vbScript code:

Code:
stPath="C:\Users\*\Desktop\mIRC.lnk"

Set wshShell=CreateObject("WScript.Shell")
Set objShortcut=wshShell.CreateShortcut(stPath)

WScript.Echo "Target Path: " & objShortcut.TargetPath


This Code will show me the target path of the indicated shortcut when i execute the shortcut.vbs

So, if somebody helps me to create an alias (/shortcut), for example, when i execute:

//echo -a $shortcut("C:\Users\Administrator\Desktop\mIRC.lnk")

will return the target path value of the input shortcut.

P.S. Will be good the alias to be created using the method of vbscript commands listed above.

Also i have, for example, an idea to save it in a vbs file and to use /run command, the value to be written in a file and so on.. but will be good if i implement this using $com objects instead.

Thanks any who will help me with this alias.

Last edited by klez; 02/04/17 10:51 AM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Code:
;; $shortcut(...)
;; $shortcut(...).TargetPath
;;     Returns the target path
;;
;; $shortcut(...).Description
;;     Returns the shortcuts decription
;;
;; All other supported properties are supported with this script
alias shortcut {
  var %file = $file($$1).longfn
  var %prop = $iif($prop, $v1, TargetPath)   
  var %com1 = $ticks $+ 000, %com2, %res
  while ($com(cmShortCut $+ %com1) || $com(cmShortCutInst $+ %com1)) {
    inc %com1
  }
  %com2 = cmShortCutInst $+ %com1
  %com1 = cmShortCut $+ %com1
  .comopen %com1 WScript.Shell
  if (!$com(%com1) || $comerr) {
    goto error
  }
  elseif (!$com(%com1, CreateShortcut, 3, bstr, %file, dispatch* %com2) || $comerr || !$com(%com2)) {
    goto error
  }
  elseif (!$com(%com2, %Prop, 2) || $comerr) {
    goto error
  }
  else {
    %res = $com(%com2).result
  }
  :error
  if ($com(%com2)) .comclose $v1
  if ($com(%com1)) .comclose $v1
  return %res
}

Last edited by FroggieDaFrog; 02/04/17 11:43 AM.

I am SReject
My Stuff
Joined: Sep 2015
Posts: 101
klez Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Sep 2015
Posts: 101
Thank you very much. It works great! If i pray you to make and another alias to create a shortcut, i'll be very thankful. Please help me. The vbscript code is:

Code:
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\Users\*\Desktop\mIRC.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "C:\Program Files\mIRCs\mIRC\mIRC.exe"
oLink.IconLocation = "C:\Program Files\mIRCs\mIRC\mIRC.exe, 22"
oLink.WorkingDirectory = "C:\Program Files\mIRCs\mIRC\"
oLink.Save


Instead of linkfile will be used $1, targetpath - $2, iconlocation - $3, workingdir - $4 .. i mean /cutcreate $1 $2 $3 $4

Last edited by klez; 03/04/17 06:36 AM.

Link Copied to Clipboard