如何阻止 Windows 快捷方式更新其路径?

Kyl*_*ney 26 windows windows-7 shortcuts path windows-10

在开发我的产品时,我的测试设备同时安装了多个版本的应用程序。但是,为了获得我的应用程序用于工作的绝对路径,我需要切换或重命名文件夹,以便我要测试的版本具有正确的路径,例如C:\Program Files\My Company\My App\My App.exe. 我已经创建了一个针对此路径的快捷方式,但是如果在当前没有任何版本具有该路径时打开此快捷方式,则该快捷方式将自动更新,认为文件已永久移动。这导致了无声的失败,直到我发现发生了什么。直到现在我才知道这是 Windows 快捷方式的功能。

所以我的问题很简单。有什么办法可以关闭这个功能吗?全局是好的,但每个快捷方式的解决方案会更好。

使用批处理文件而不是快捷方式是一种解决方案,但我想知道是否有任何方法可以在仍然使用快捷方式的同时使这项工作有效。

我正在使用 Windows 10 家庭版和 Windows 7 家庭版。

Ste*_*ven 26

停止并禁用服务:分布式链路跟踪客户端 (TrkWks)。

分布式链接跟踪在链接到 NTFS 卷上的文件的情况下跟踪链接,例如外壳快捷方式。如果该文件被重命名、移动到同一台计算机上的另一个卷、移动到另一台计算机或在其他类似情况下移动,Windows 将使用分布式链接跟踪来查找文件。

来源:分布式链接跟踪 - Microsoft 支持

  • “找到正确的目标”功能可以追溯到 Windows 9x 系列,并且早于 Windows 的 NT 版本。Windows 9x 上不存在 DLT。这并不是说 DLT 无关紧要;如果有助于找到快捷方式目标,Windows *将*使用 DLT。 (10认同)
  • @Steven 是的,我确定该服务已关闭。在Windows 10中,我进入Services,找到Distributed Link Tracking Client,点击停止按钮,重启我的电脑,再次检查服务。有一个“开始”按钮,但该服务没有说正在运行。快捷方式仍会自行更新。 (2认同)

Ben*_*n N 14

您可以使用 PowerShell!这个小脚本重击 LNK 文件以产生与使用经典shortcut实用程序相同的效果。

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

要使用它,将该文本保存为.ps1文件,例如notrack.ps1. 如果您还没有,请按照PowerShell 标记 wiki的启用脚本部分中说明进行操作。然后您可以从 PowerShell 提示符运行它:

.\notrack.ps1 C:\path\to\my\shortcut.lnk
Run Code Online (Sandbox Code Playgroud)

以这种方式调整的快捷方式在目标移动时不会改变。如果像这样的快捷方式被破坏,当您尝试打开它时什么也不会发生。

我从这个 LNK 格式的 48 页 Microsoft PDF 中收集了我的脚本中使用的二进制数学。


Sun*_*nzi 7

使用shortcut.exe命令选项-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
Run Code Online (Sandbox Code Playgroud)

  • 遗憾的是,shortcut.exe 不再可用。 (4认同)
  • @Daniel 你知道哪些版本的 Windows 有吗?它可能对某些人有用。 (2认同)

Swi*_*one 5

您可以启用以下 GPO:

用户配置\管理模板\开始菜单和任务栏\解析外壳快捷方式时不要使用基于搜索的方法

对应的注册表项: HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoResolveSearch

用户配置\管理模板\开始菜单和任务栏\解析外壳快捷方式时不要使用基于跟踪的方法

对应的注册表项:

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoResolveTrack
Run Code Online (Sandbox Code Playgroud)

用户配置\管理模板\Windows 组件\文件资源管理器\漫游期间不跟踪外壳快捷方式

对应的注册表项: HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\LinkResolveIgnoreLinkInfo