I am trying to pin a program to the taskbar in Windows 10 (RTM) using this code:
$shell = new-object -com "Shell.Application" $folder = $shell.Namespace((Join-Path $env:SystemRoot System32\WindowsPowerShell\v1.0)) $item = $folder.Parsename('powershell_ise.exe') $item.invokeverb('taskbarpin');
This worked on Windows 8.1, but no longer works on Windows 10.
If I execute $item.Verbs()
, I get these:
Application Parent Name ----------- ------ ---- &Open Run as &administrator &Pin to Start Restore previous &versions Cu&t &Copy Create &shortcut &Delete Rena&me P&roperties
As you can see, there is no verb for pinning it to the taskbar. If I right click that specific file, however, the option is there:
Questions:
Am I missing something?
Is there a new way in Windows 10 to pin a program to the taskbar?
Open Control Panel through the Start menu or a desktop icon – whatever method you use to launch it. Then once it's open, the Control Panel button will be displayed on the Taskbar. Right-click on it and select Pin this Program to Taskbar. That's it.
To pin apps to the taskbarSelect Start , scroll to the app you want to pin, then press and hold (or right-click) the app. Select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.
Very nice! I made a few small tweaks to that powershell example, I hope you don't mind :)
param ( [parameter(Mandatory=$True, HelpMessage="Target item to pin")] [ValidateNotNullOrEmpty()] [string] $Target ) if (!(Test-Path $Target)) { Write-Warning "$Target does not exist" break } $KeyPath1 = "HKCU:\SOFTWARE\Classes" $KeyPath2 = "*" $KeyPath3 = "shell" $KeyPath4 = "{:}" $ValueName = "ExplorerCommandHandler" $ValueData = (Get-ItemProperty ` ("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\" + ` "CommandStore\shell\Windows.taskbarpin") ).ExplorerCommandHandler $Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true) $Key3 = $Key2.CreateSubKey($KeyPath3, $true) $Key4 = $Key3.CreateSubKey($KeyPath4, $true) $Key4.SetValue($ValueName, $ValueData) $Shell = New-Object -ComObject "Shell.Application" $Folder = $Shell.Namespace((Get-Item $Target).DirectoryName) $Item = $Folder.ParseName((Get-Item $Target).Name) $Item.InvokeVerb("{:}") $Key3.DeleteSubKey($KeyPath4) if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) { $Key2.DeleteSubKey($KeyPath3) }
Here's Humberto's vbscript solution ported to PowerShell:
Param($Target) $KeyPath1 = "HKCU:\SOFTWARE\Classes" $KeyPath2 = "*" $KeyPath3 = "shell" $KeyPath4 = "{:}" $ValueName = "ExplorerCommandHandler" $ValueData = (Get-ItemProperty("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\" + "Explorer\CommandStore\shell\Windows.taskbarpin")).ExplorerCommandHandler $Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true) $Key3 = $Key2.CreateSubKey($KeyPath3, $true) $Key4 = $Key3.CreateSubKey($KeyPath4, $true) $Key4.SetValue($ValueName, $ValueData) $Shell = New-Object -ComObject "Shell.Application" $Folder = $Shell.Namespace((Get-Item $Target).DirectoryName) $Item = $Folder.ParseName((Get-Item $Target).Name) $Item.InvokeVerb("{:}") $Key3.DeleteSubKey($KeyPath4) if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) { $Key2.DeleteSubKey($KeyPath3) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With