Modify shortcut file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Modify shortcut file

30 May 2016, 01:52

AHK offers two commands to work with shortcut files (.lnk).
FileSetShortcut and FileGetShortcut

I would like to modify the target of an existing shortcut file.

What can be done to modify an existing shortcut file?
Of cause I could delete the old and create a new one.
But is there a way to modify an existing shortcut file?

PS: I am planing to write a short script that searches for broken shortcuts (e.g. due to moving or deleting files) on a server and offers to correct the target or to delete the shortcut, similar to the shareware program Shortcut Doctor. If you have any hint on such a script or other program that does such a task, please post as well. Thanks a lot in advance.
ciao
toralf
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Modify shortcut file

30 May 2016, 02:11

The easiest way is probably using the Windows Scripting Host COM interface:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; https://msdn.microsoft.com/en-us/library/xsy6k3ys(v=vs.84).aspx
; https://msdn.microsoft.com/en-us/library/xk6kst2k(v=vs.84).aspx
wsh := ComObjCreate("WScript.Shell")
lnk := wsh.CreateShortcut("<path to existing lnk file or one to create>")
lnk.TargetPath := "D:\"
lnk.Save()
Otherwise, using the IShellLink(A/W) interface, like FileCreateShortcut does, is an option.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Modify shortcut file

30 May 2016, 10:28

ciao
toralf

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, Rohwedder, Seven0528 and 322 guests