我想创建一个在 Windows 7 任务栏中创建快捷方式的 powershell 脚本,该脚本从 cmd.exe 运行批处理文件。
尝试按照这两个帖子中的说明进行操作:
- https://superuser.com/questions/100249/how-to-pin-either-a-shortcut-or-a-batch-file-to-the-new-windows-7-taskbar
- 如何使用 Powershell 创建快捷方式
基本上我想将快捷方式文件的目标属性设置为:
C:\Windows\System32\cmd.exe /C "C:\Dev\Batch files\cmake-guiMSVC1064bit.bat"
到目前为止,我在我的 powershell 脚本中得到的是:
$batchPath = "C:\Dev\my_batchfile.bat"
$taskbarFolder = "$Home\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\Taskbar\"
$cmdPath = (Get-Command cmd | Select-Object Definition).Definition
$objShell = New-Object -ComObject WScript.Shell
$objShortCut = $objShell.CreateShortcut("$shortcutFolder\$batchName.lnk")
#TODO problem ... :(
$objShortCut.TargetPath = "$cmdPath /C $batchPath"
$objShortCut.Save()
这会导致以下错误:
Exception setting "TargetPath": "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" At C:\Dev\Powershell\GetTools.ps1:220 char:18
+ $objShortCut. <<<< TargetPath = "$cmdPath /C $batchPath"
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
有人有什么建议吗?