【发布时间】:2020-09-25 22:23:41
【问题描述】:
我需要在 Windows 2019 Server 上为 Eclipse 应用程序创建一个快捷方式,以便它运行 PowerShell 脚本而不是打开 Eclipse。该脚本首先运行一些命令,然后打开 Eclipse 应用程序。当我编辑 Eclipse 的现有快捷方式时,我可以将目标修改为:
"powershell.exe -ExecutionPolicy bypass C:\temp\eclipse-fix.ps1 -WindowStyle Hidden"
手动完成时效果很好。但是,当我尝试对 PowerShell 脚本执行相同操作以自动执行该过程时,出现错误。
脚本内容:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("C:\Users\Administrator\Desktop\Eclipse.lnk")
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy bypass C:\cfn\temp\eclipse-fix.ps1 -WindowStyle Hidden"
$Shortcut.IconLocation = "%SystemDrive%\eclipse\eclipse.exe"
$Shortcut.Save()
错误返回:
PS C:\Users\Administrator> $WshShell = New-Object -comObject WScript.Shell
PS C:\Users\Administrator> $Shortcut = $WshShell.CreateShortcut("C:\Users\Administrator\Desktop\Eclipse.lnk")
PS C:\Users\Administrator> $Shortcut.TargetPath = "powershell.exe -File C:\cfn\temp\eclipse-fix.ps1"
Value does not fall within the expected range.
At line:1 char:1
+ $Shortcut.TargetPath = "powershell.exe -File C:\cfn\temp\eclipse-fix. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
PS C:\Users\Administrator> $Shortcut.IconLocation="%SystemDrive%\eclipse\eclipse.exe, 0"
PS C:\Users\Administrator> $Shortcut.Save()
结果:
图标已创建,但没有目标值。
有谁知道我缺少什么才能让它工作?还有其他我可能不知道的选项吗?
谢谢。
【问题讨论】:
标签: windows powershell wsh