The following code will pin a metro app to start given an AUMID
If you change
-match 'Pin To Start'
Unfortunately changing the match to 'Pin To Taskbar' does not work. What is going on here?
function Pin-Taskbar { param( [string]$aumid, [switch]$unpin ) try{ if ($unpin.IsPresent){ ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Path -eq $aumid}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from Taskbar'} | %{$_.DoIt()} return "App '$aumid' unpinned from Taskbar" }else{ ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Path -eq $aumid}).Verbs() | ?{$_.Name.replace('&','') -match 'Pin to Taskbar'} | %{$_.DoIt()} return "App '$aumid' pinned to Taskbar" } }catch{ Write-Error "Error Pinning/Unpinning App! (App-Name correct?)" } } Pin-Taskbar king.com.CandyCrushSaga_kgqvnymyfvs32!App
2 Answers
Answers 1
I assume you are a good citizen and do not want to spam the taskbar of the users.
In previous versions of Windows, you were able to use the verb Pintotaskbar
to programmatically un-/pin programs to your taskbar.
$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 no longer works in Windows 10. The verb Pintotaskbar
simply does not exist anymore.
Hence, an unapproved 3rd-party command prompt utility called SysPin was brought to life - that allows you to do exactly what you want (though it does not work with each and every app).
However, since Windows 10 version 1607 there is a new official way: adding a <TaskbarLayout>
See: Customize Pinned Items on Taskbar in Windows 10 1607 during OSD with ConfigMgr
Answers 2
Microsoft doesn't want you to be able to pin items to the taskbar programmatically, but the way they prevented it is pretty weak.
Despite what some people say, the verbs exists, the handlers exists. Everything still exists.
The standard handler for "Pin to Taskbar" is still documented at the Registering Shell Extension Handlers page, and the following keys and values exist in the Registry of my Windows 10 machine:
[HKEY_CLASSES_ROOT\CLSID\{90AA3A4E-1CBA-4233-B8BB-535773D48449}] @="Taskband Pin" "ImplementsVerbs"="taskbarpin;taskbarunpin" [HKEY_CLASSES_ROOT\CLSID\{90AA3A4E-1CBA-4233-B8BB-535773D48449}\InProcServer32] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,00,68,00,\ 65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,00,00,00 "ThreadingModel"="Apartment"
And this CLSID is still registered as one of the shell context menu handlers:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}] @="Taskband Pin"
Check your own registry.
(The hex mess is REG_EXPAND_SZ for "%SystemRoot%\system32\shell32.dll".)
The only thing that changed is that when enumerating the verbs implemented etc. they check the process name. If it's "explorer.exe" they include (un)pin to taskbar. Otherwise they skip it. That's all.
Make a copy of PowerShell called "explorer.exe" and run your script from it. Suddenly everything works. They don't actually make sure the process is the real explorer.exe, just that the process is named that way.
0 comments:
Post a Comment