25

While developing my product, my test device has several versions of the application installed at the same time. However, in order to get the absolute paths that my application is using to work, I need to switch out or rename the folders so that the version I want to test has the right path, say C:\Program Files\My Company\My App\My App.exe. I've made a shortcut that targets this path, but if this shortcut is opened when none of the versions currently have that path then the shortcut will automatically update itself, thinking the file has moved permanently. This caused silent failures until I discovered what was happening. I didn't know this was a feature of Windows shortcuts until now.

So my question is simple. Is there any way to turn this feature off? Globally is good but a per-shortcut solution would be better.

Using a batch file instead of a shortcut is one solution, but I'm wondering if there's any way to make this work while still using a shortcut.

I'm using Windows 10 Home and Windows 7 Home.

  • 10
    What I've done in the past is use a batch file (.bat) with a simple command, e.g. start "" "C:\path\to\file.exe". – Bob Jul 19 '17 at 2:25
  • 1
    Have you tried creating a symbolic link (using the mklink command) instead of a .lnk file instead? Or do those get updated too? – JAB Jul 19 '17 at 2:55
  • 1
    @JAB symlinks shouldn't be updated, but have certain disadvantages (require admin privs, cannot pass arguments, etc.). Though they do work well if those aren't a problem. – Bob Jul 19 '17 at 3:04
  • 3
    I thought making the shortcut read-only would work (I'm sure it used to) but having tested I see that it doesn't. This is because the shortcut isn't rewritten; the target is found when the shortcut is run. Just so no-one else tries. – Chris H Jul 19 '17 at 9:37
  • 1
    @PetSerAl as I said above, that doesn't work. – Chris H Jul 20 '17 at 13:01
13

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.

25

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

  • Good idea, but remarkably it didn't work. The shortcut still found the file even when the path was one directory longer. – Kyle Delaney Jul 18 '17 at 21:05
  • Are you sure the service is stopped? After stopping the DLTC service, I moved or renamed the executable. When I ran the shortcut, I got a "Problem with Shortcut" error saying the target is missing and prompting to delete the shortcut. – Steven Jul 19 '17 at 3:02
  • 10
    The "find the right target" functionality dates back to the Windows 9x series, and predates the NT versions of Windows. DLT didn't exist on Windows 9x. That's not to say DLT is irrelevant; Windows will use DLT if that helps to find a shortcut target. – MSalters Jul 19 '17 at 7:19
  • 2
    @Steven Yes, I'm sure the service is turned off. In Windows 10, I went into Services, found Distributed Link Tracking Client, clicked the stop button, restarted my computer, and checked the service again. There's a Start button and the service doesn't say running. Shortcuts still update themselves. – Kyle Delaney Jul 19 '17 at 13:56
8

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
  • 4
    Sadly, shortcut.exe is no longer readily available. – Daniel B Jul 19 '17 at 8:25
  • @DanielB You're right, I've forgot that I've rescued shortcut.exe over some Versions of Windows. – Sunzi Jul 19 '17 at 8:44
  • 2
    @Daniel do you know which versions of Windows have it? It could be useful for some people. – gronostaj Jul 19 '17 at 12:40
  • 1
    It’s apparently part of the Windows NT4 Server Resource Kit. It was originally made available on CD. – Daniel B Jul 19 '17 at 12:48
4

You can enable the following GPO:

User Configuration\Administrative Templates\Start Menu and Taskbar\Do not use the search-based method when resolving shell shortcuts

corresponding registry key: HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoResolveSearch

User Configuration\Administrative Templates\Start Menu and Taskbar\Do not use the tracking-based method when resolving shell shortcuts

corresponding registry key:

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoResolveTrack

User Configuration\Administrative Templates\Windows Components\File Explorer\Do not track shell shortcuts during roaming

corresponding registry key: HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\LinkResolveIgnoreLinkInfo

  • How do I enable a GPO? Where do I find User Configuration? – Kyle Delaney Jul 19 '17 at 14:01
  • on windows 10 you can right click on the start button -> Run and write: gpedit.msc -> click OK, then you will be able to find User configuration, etc... OR you can create the registry keys that I specified (Type : DWORD, with a value of 1) – Swisstone Jul 19 '17 at 14:14
  • I got an error. Windows couldn't find gpedit.msc. – Kyle Delaney Jul 19 '17 at 14:16
  • OK, so you must create the keys manually in the registry. If you don't know how to do that, I created a .reg file that you can import: pastebin.com/KdPYFwff just copy-paste the content in a new file that must end with the ".reg" extension (not .txt) and double click on it – Swisstone Jul 19 '17 at 14:22
  • Thanks. I did it, restarted my computer, and verified that the registry keys were now in place using regedit. Shortcuts still update themselves. – Kyle Delaney Jul 19 '17 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.