3
我想创建一个powershell脚本,它在Windows 7任务栏中创建一个快捷方式,该快捷方式从cmd.exe运行批处理文件。创建运行批处理文件的快捷方式
试图做的是告诉记者,在这两个职位:
- https://superuser.com/questions/100249/how-to-pin-either-a-shortcut-or-a-batch-file-to-the-new-windows-7-taskbar
- How to create a shortcut using Powershell
基本上我想设置一个快捷方式文件目标属性是这样的:
C:\Windows\System32\cmd.exe /C "C:\Dev\Batch files\cmake-guiMSVC1064bit.bat"
我到目前为止在我的PowerShell中CRIPT是:
$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
任何人有什么建议吗?
我已经有批处理文件,只需要做的是创建一个快捷方式,其中目标属性是像一个PowerShell脚本:C:\ Windows \ System32下\ cmd.exe/C“C:\ Dev \批处理文件\ cmake-guiMSVC1064bit.bat” –
为什么不右击批处理文件 - >创建快捷方式...? –
因为这是一个较大的脚本的一部分,应该在多台机器上运行,并且最少需要人工交互。 :) –