Friday, July 21, 2017

Preventing a single shortcut from tracking its target

Windows shortcuts will attempt to find their target if it doesn't exist in the path it knew about. In some use cases, though, that might not be the most desirable behavior. There doesn't seem to be a way to disable the tracking behavior in the GUI - even stopping the Distributed Link Tracking Client service won't stop ye olde search through adjacent/ancestor/descendant directories.

Someone mentioned the shortcut utility from an old Resource Kit. Unfortunately, it's not easily available. The mention that it could work that change on one shortcut told me that something in the shortcut file could disable the tracking. So I skimmed the official format spec on the LNK format. On page 12, it introduces the LinkFlags field, a four-byte value with 25 different flags defined. A few of those in the third byte (byte 0x16 from the beginning) looked relevant, so I threw together a PowerShell script that set them. Sure enough, it worked.

$linkfile = Resolve-Path $args[0]
$bytes = [IO.File]::ReadAllBytes($linkfile)
$bytes[0x16] = $bytes[0x16] -bor 0x36
[IO.File]::WriteAllBytes($linkfile, $bytes)

Weirdly, if a shortcut altered like this is broken (i.e. its target goes missing), no dialog is created to tell you about that, at least on Windows 10.

No comments:

Post a Comment