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

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

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

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

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

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

答案1

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

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

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

.\notrack.ps1 C:\path\to\my\shortcut.lnk

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

我从以下来源收集了脚本中使用的二进制数学这份 48 页的 LNK 格式 Microsoft PDF

答案2

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

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

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

答案3

使用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

答案4

我不确定超级用户是否会鄙视 necroposting(我第一次发帖),但我可以确认这有效......如果你能够让本地组策略编辑器(LGPE)在 Windows 11 Home 上运行。

背景:我买了一台定制电脑,出于自己的愚蠢,买了家庭版而不是专业版,直到为时已晚才意识到这一点。正如上面其他人所建议的那样,LGPE 在 Win 11 Home 上并不容易获得,但可以恢复

解决方案:我通过以管理员身份运行 MajorGeeks 中的批处理文件恢复了 LGPE。是的,从不受信任的来源下载批处理文件很危险。幸运的是,我信任 MajorGeeks,而且我在像白痴一样盲目运行批处理文件之前通过 Edit 检查了它。它直接指向您 PC 上已有的路径,而不是某些外部来源。

详细的操作方法显示 Youtube 视频并包含带有批处理文件的页面链接:https://www.majorgeeks.com/content/page/enable_group_policy_editor_in_windows_10_home_edition.html

不幸的是,这两种方法都建议从他们那里下载文件,所以我肯定有些人不会喜欢这个。我对批处理文件命令的理解是,它运行一个已经在 %SystemRoot% 文件路径深处列出的包文件。所以如果你知道如何找到它,你很可能可以自己做这件事——但你在这里读这篇文章的事实可能意味着你不知道怎么做。

下面我将粘贴上述批处理文件中的命令,但不包括 @echo 命令,这些命令只是来自 MajorGeeks 的有用的指导性评论,并带有指向其网站的链接

pushd "%~dp0" 

dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt 
dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt 

for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" 
pause

相关内容