4

Windows 7 のタスクバーにショートカットを作成し、cmd.exe からバッチ ファイルを実行する powershell スクリプトを作成したいと考えています。

これらの2つの投稿で言われたようにしようとしています:

  1. https://superuser.com/questions/100249/how-to-pin-either-a-shortcut-or-a-batch-file-to-the-new-windows-7-taskbar
  2. Powershell を使用してショートカットを作成する方法

基本的に、ショートカット ファイルの Target プロパティを次のように設定します。

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

誰にも何か提案がありますか?

4

1 に答える 1

10

Argumentsプロパティを使用して引数を設定します。

$batchName = 'cmd'
$batchPath="D:\Temp\New folder\test.bat"
$taskbarFolder = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\Taskbar\"
$objShell = New-Object -ComObject WScript.Shell
$objShortCut = $objShell.CreateShortcut("$taskbarFolder\$batchName.lnk")
$objShortCut.TargetPath = 'cmd'
$objShortCut.Arguments="/c ""$batchPath"""
$objShortCut.Save()
于 2012-06-19T07:52:04.737 に答える