Get Windows Shortcut Target


  1. 說明
  2. 參考資料

筆記如何使用 PowerShell 取得 Windows 捷徑檔 (lnk) 的目標與相關資訊。

logo

說明

$sh = New-Object -ComObject WScript.Shell
$sh.CreateShortcut("C:\temp\quick.lnk")

可以觀察到的資訊:

FullName         : C:\temp\quick.lnk
Arguments        :
Description      :
Hotkey           :
IconLocation     : ,0
RelativePath     :
TargetPath       : D:\Files\6d3b9288-b55e-4125-a6b7-efa6d3a57d4a
WindowStyle      : 1
WorkingDirectory :

Lnk 令人感到神奇的是如目的的資料夾 Rename,Lnk 也會配合調整 Target 找到新目標資料夾,而如果是原本的資料夾名稱被賦予新資料夾,則會另指向新資料夾 🤔

參考資料

How to create a desktop shortcut with the Windows Script Host | learn.microsoft