How do I stop a Windows shortcut from updating its path?
Stop and disable the service: Distributed Link Tracking Client (TrkWks).
Distributed Link Tracking tracks links in scenarios where the link is made to a file on an NTFS volume, such as shell shortcuts. If that file is renamed, moved to another volume on the same computer, moved to another computer, or moved in other similar scenarios, Windows uses Distributed Link Tracking to find the file.
Source: Distributed Link Tracking - Microsoft Support
You can use PowerShell! This little script whacks the LNK file to produce the same effect as using the classic shortcut
utility.
$linkfile = Resolve-Path $args[0]
$bytes = [IO.File]::ReadAllBytes($linkfile)
$bytes[0x16] = $bytes[0x16] -bor 0x36
[IO.File]::WriteAllBytes($linkfile, $bytes)
To use it, save that text as a .ps1
file, e.g. notrack.ps1
. If you haven't already, follow the instructions in the Enabling Scripts section of the PowerShell tag wiki. Then you can run it from a PowerShell prompt:
.\notrack.ps1 C:\path\to\my\shortcut.lnk
Shortcuts that are tweaked in this way will not change when their target moves. If a shortcut like this gets broken, nothing at all will happen when you try to open it.
I gathered the binary math used in my script from this 48-page Microsoft PDF on the LNK format.
Use the shortcut.exe
command Option -s
:
shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working directory]
[-a Arguments] [-i Iconfile] [-x Icon index] [-u {all|[natdix]}]
[-l logfile]
-? -h This help
-f Force overwrite of an existing short cut
-c Change existing shortcut
-s Make shortcut non tracking (Stupid)
-r Resolve broken shortcut
-t target Specifies the target of the shortcut
-n name Specifies the file name of the shortcut file
-d directory Specifies the directory name to start the application in
-a arguments Specifies the arguments passed when the shortcut is used
-i iconfile Specifiles the file the icon is in
-x index Specifies the index into the icon file
-u [spec] Dumps the contents of a shortcut. 'all' is the same as 'natdix'
but the letters of 'natdix' can be specified to display specific
fields in the shortcut (repeats allowed, and order followed)
-l logfile record error messages in specified file