Change target path in a windows shortcut file

Ken Ray kray at sonsothunder.com
Sun Mar 6 14:07:13 EST 2005


On 3/6/05 12:40 PM, "Alejandro Tejada" <capellan2000 at yahoo.com> wrote:

> Hi Developers,
> 
> Does exist some way to change the target
> path of a shortcut file from within Runrev?
> 
> The target path of a shortcut is the
> path to the file that windows will
> open when you double click on the
> shortcut.
> 
> I suspect that there are two possible ways
> to do this:
> 
> 1- a shell DOS command could work
> (but still i have not find a dos command
> that could read or write shortcut files)
> 
> or 
> 
> 2- writing the new target path directly in
> the binary file... but is this reliable???
> 
> any other way to do this task?

Yes, you can use VBScript. However in doing so, you may trigger virus
protection software.

Here's the basic .vbs script, with placeholders surrounded in double angle
brackets << >> :

----
Set wso = CreateObject("WScript.Shell")
Set link = wso.CreateShortcut("<<PATH_TO_SHORTCUT_FILE>>")
link.targetPath = "<<NEW_TARGET_PATH>>"
link.save
----

Now put that into a custom property, and then when you need it, retrieve it,
replace the placeholders with real file paths (remember to convert the
"/"-delimited paths that Rev uses to "\"- delimited ones for Windows), and
then run it like this:

on ChangeShortCut pPathToShortcut,pNewTargetPath
  replace "/" with "\" in pPathToShortcut
  replace "/" with "\" in pNewTargetPath
  put the uVBScript of this stack into tScript
  replace "<<PATH_TO_SHORTCUT_FILE>>" with pPathToShortCut in tScript
  replace "<<NEW_TARGET_PATH>>" with pNewTargetPath in tScript
  runScript tScript
end ChangeShortCut

on runScript pVBS
  set the hideConsoleWindows to true
  put "C:\temp.vbs" into tTempPath
  put pVBS into url ("file:" & tTempPath)
  get shell("cscript.exe //nologo" && tTempPath)
  send "delete file" && quote & tTempPath & quote to me in 1 second
  -- this gives enough time for the script to run before you delete it
end runScript

------

Of course, in retrospect, you could *always* just delete the old shortcut
and create a new one with 'create alias'... but it's your call...

HTH,


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list