【问题标题】:Creating Windows Shortcuts with Powershell, problems with spaces in the Target Path使用 Powershell 创建 Windows 快捷方式,目标路径中的空格问题
【发布时间】:2012-03-20 19:07:55
【问题描述】:

简短而甜蜜,我正在 PS 中制作快捷方式,只要目标路径中没有空格,快捷方式就可以正常工作。一旦目标中有一个空格,快捷方式目标就会用双引号括起来,因此不起作用......下面是非工作代码。如果你要删除它会正确的空间(除了它当时没有指向EXE的事实)。基本上它不会将目标用引号括起来。

$shell = New-Object -ComObject WScript.Shell
$shortcutX = $shell.CreateShortcut("C:\Short.lnk")
$shortcutX.TargetPath = "C:\apps\application --switch"
$shortcutX.Save()

TL;DR:

工作。

$shortcutX.TargetPath = "C:\apps\application"

没用!

$shortcutX.TargetPath = "C:\apps\application --switch"

为什么?!?!?!?!

【问题讨论】:

    标签: windows-7 powershell shortcut


    【解决方案1】:

    来自MSDN

    此属性仅适用于快捷方式的目标路径。

    您可以在 Argument 的属性中为快捷方式添加参数。

    $shortcutX.Arguments = "-- switch"
    

    在我的盒子(Windows 7 Pro)上,我可以使用带有空格的路径目标创建快捷方式。

    【讨论】:

      猜你喜欢
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 1970-01-01
      • 2021-08-25
      • 2021-10-04
      • 2018-07-17
      • 2010-10-11
      相关资源
      最近更新 更多