How do I stop a Windows shortcut from updating its path?

9,356

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 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

Share:
9,356

Related videos on Youtube

Kyle Delaney
Author by

Kyle Delaney

Updated on September 18, 2022

Comments

  • Kyle Delaney
    Kyle Delaney over 1 year

    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.

    • tvdo
      tvdo almost 7 years
      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".
    • JAB
      JAB almost 7 years
      Have you tried creating a symbolic link (using the mklink command) instead of a .lnk file instead? Or do those get updated too?
    • tvdo
      tvdo almost 7 years
      @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.
    • Chris H
      Chris H almost 7 years
      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.
    • Kyle Delaney
      Kyle Delaney almost 7 years
      @Bob I believe you don't need start. Just "C:\path\to\file.exe" should work as the entire batch file, right?
    • tvdo
      tvdo almost 7 years
      @KyleDelaney True, if you provide the full path then start isn't necessary. I use it because I tend to combine it with App Paths, which only work with the ShellExecute family (including start).
    • user364455
      user364455 almost 7 years
      Mark shortcut as read-only.
    • Chris H
      Chris H almost 7 years
      @PetSerAl as I said above, that doesn't work.
    • user364455
      user364455 almost 7 years
      @ChrisH It work for me. Even when Windows can find moved file, it does not update path in shortcut. And when you then create new file in original shortcut location target, it will open that new file.
    • Chris H
      Chris H almost 7 years
      @PetSerAl The OP's problem appears to be that clicking an obsolete shortcut launches a different version. Read-only doesn't solve that. It just means the search has to happen again next time.
    • user364455
      user364455 almost 7 years
      @ChrisH As long as file at shortcut target path exist, no search will be performed and that file will be used, even if it is not the file, from which shortcut was created. So, only practical difference from .bat/.cmd solution is that: if file does not exist, it will not fail, but try to find original file. Otherwise behavior would be identical.
    • Chris H
      Chris H almost 7 years
      @PetSerAl exactly. My reading (and that of those who wrote the answers including the accepted one) is that the OP wants an obsolete link to fail rather than silently pointing to an arbitrary more recent version. Running/testing multiple versions of software is hard enough without Windows trying to help.
    • user364455
      user364455 almost 7 years
      @ChrisH I do not see where OP ask that it must fail in that case. OP ask how to prevent shortcut from updating, not how to prevent Windows from searching for moved file. And read-only doing exactly that: prevent shortcut from updating. You must have very great mind reading capabilities, as you not only can correctly understand what OP want, but also assert that others (that of those who wrote the answers including the accepted one) have the same understanding of question as you.
  • Kyle Delaney
    Kyle Delaney almost 7 years
    Good idea, but remarkably it didn't work. The shortcut still found the file even when the path was one directory longer.
  • Steven
    Steven almost 7 years
    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.
  • MSalters
    MSalters almost 7 years
    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.
  • Daniel B
    Daniel B almost 7 years
    Sadly, shortcut.exe is no longer readily available.
  • Sunzi
    Sunzi almost 7 years
    @DanielB You're right, I've forgot that I've rescued shortcut.exe over some Versions of Windows.
  • gronostaj
    gronostaj almost 7 years
    @Daniel do you know which versions of Windows have it? It could be useful for some people.
  • Daniel B
    Daniel B almost 7 years
    It’s apparently part of the Windows NT4 Server Resource Kit. It was originally made available on CD.
  • Kyle Delaney
    Kyle Delaney almost 7 years
    @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
    Kyle Delaney almost 7 years
    How do I enable a GPO? Where do I find User Configuration?
  • Swisstone
    Swisstone almost 7 years
    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)
  • Kyle Delaney
    Kyle Delaney almost 7 years
    I got an error. Windows couldn't find gpedit.msc.
  • Swisstone
    Swisstone almost 7 years
    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
  • Kyle Delaney
    Kyle Delaney almost 7 years
    Thanks. I did it, restarted my computer, and verified that the registry keys were now in place using regedit. Shortcuts still update themselves.
  • Run5k
    Run5k almost 7 years
    Windows couldn't find gpedit.msc @KyleDelaney, which version of Windows are you using? The text of your question doesn't tell us, you list two different versions within the tags, and you didn't specify whether it is Home or Pro.
  • Canadian Luke
    Canadian Luke almost 7 years
    @Run5k If Windows can't find gpedit.msc, which is a non-Home/non-Starter edition MMC snapin, then it's safe to assume he's using the Home versions of Windows
  • Run5k
    Run5k almost 7 years
    @CanadianLuke, yes, I realize that... but the OP doesn't, and my goal was to emphasize the importance of telling us the exact version of Windows that the workstation is utilizing within the text of the original question. It can help the potential contributors save quite a bit of time and effort.
  • Kyle Delaney
    Kyle Delaney almost 7 years
    @Run5k I've updated it.