Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate shortcut that runs a batch file
    text
    copied!<p>I want to create a powershell script that creates a shortcut in the windows 7 taskbar, that runs a batch file from cmd.exe.</p> <p>Trying to do as told in these two posts:</p> <ol> <li><a href="https://superuser.com/questions/100249/how-to-pin-either-a-shortcut-or-a-batch-file-to-the-new-windows-7-taskbar">https://superuser.com/questions/100249/how-to-pin-either-a-shortcut-or-a-batch-file-to-the-new-windows-7-taskbar</a></li> <li><a href="https://stackoverflow.com/questions/9701840/how-to-create-a-shortcut-using-powershell-or-cmd">How to create a shortcut using Powershell</a></li> </ol> <p>Basically I want to set a shortcut files Target property to be something like:</p> <pre><code>C:\Windows\System32\cmd.exe /C "C:\Dev\Batch files\cmake-guiMSVC1064bit.bat" </code></pre> <p>What I got so far in my powershell script is:</p> <pre><code>$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() </code></pre> <p>This results in the following error: </p> <pre><code>Exception setting "TargetPath": "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" At C:\Dev\Powershell\GetTools.ps1:220 char:18 + $objShortCut. &lt;&lt;&lt;&lt; TargetPath = "$cmdPath /C $batchPath" + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException </code></pre> <p>Anyone got any suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload