我有一个不会正确更新 $TargetFile 的 powershell 脚本。这是我的代码:
$TargetFile = "C:\Users\wjschan\AppData\Roaming\DAS Toolbox\DAS Toolbox.exe"
$ShortcutFile = "$StartMenuPath\$ApplicationName.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$NewTarget = $TargetFile
$Shortcut.TargetPath = $TargetFile
$Shortcut.IconLocation = $IconLocation
$Shortcut.Save()
但是当我右键单击快捷方式时,它会将“这台电脑”列为目标。但是,如果我把这段代码放进去,它工作正常:
$ShortcutFile = "$StartMenuPath\$ApplicationName.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$NewTarget = $TargetFile
$Shortcut.TargetPath = "C:\Users\wjschan\AppData\Roaming\DAS Toolbox\DAS Toolbox.exe"
$Shortcut.IconLocation = $IconLocation
$Shortcut.Save()
我不知道为什么硬编码文件路径有效但变量无效。如果 $TargetFile 指向不同的路径(比如网络共享),它之前可以工作。
Win10,Build 1607(当前业务分支)-不,我无法获得更新的版本。