├── README.md └── TaskbarPinning.ps1 /README.md: -------------------------------------------------------------------------------- 1 | # Add Application to Windows 10 Taskbar 2 | # Remove Application from Windows 10 Taskbar 3 | # PowerShell-Functions for Taskbar-Pinning in Windows 10 4 | 5 | This small powershell Script adds or removes your own Applications from / to Windows 10 Taskbar (Taskbar-Pinning). The functionality is a bit tricky in Windows 10 as Microsoft doesn't like to offer Applications to pin themselves during installation. 6 | 7 | Script: [TaskbarPinning.ps1](TaskbarPinning.ps1) 8 | 9 | Tested with: Windows 10 v1709 (English & German) 10 | 11 | ## Usage: Variant 1: Pin / Unpin regular Executables (no UWP Apps) 12 | ```powershell 13 | Import-Module .\TaskbarPinning.ps1 14 | 15 | # Add Taskbar-Pinning 16 | Add-TaskbarPinning("C:\Windows\Notepad.exe") 17 | 18 | # Remove Taskbar-Pinning 19 | Remove-TaskbarPinning("C:\Windows\Notepad.exe") 20 | ``` 21 | 22 | ## Usage: Variant 2: Pin / Unpin Applications and UWP Apps already listed in Start Menu 23 | Note: Handling Add-/Remove-TaskbarPinningApp can only be done by Processes named `explorer` 24 | Workaround to do this with Powershell: Make a copy of PowerShell named explorer.exe in Temp-Directory and use this 25 | ```powershell 26 | copy $env:windir\System32\WindowsPowerShell\v1.0\powershell.exe $env:TEMP\explorer.exe 27 | 28 | & $env:TEMP\explorer.exe 29 | Import-Module .\TaskbarPinning.ps1 30 | ``` 31 | 32 | List all by Explorer known Apps containing a given Subtring 33 | ```powershell 34 | List-ExplorerApps("Microsoft") 35 | ``` 36 | Shows a List like this: 37 | ``` 38 | Name Value 39 | ---- ----- 40 | {6D809377-6AF0-444B-8957-A3773F02200E}\Microsoft\Web Platform Installer\WebPlatformInstaller.exe Microsoft Web Platform Installer 41 | Microsoft.ConnectivityStore_8wekyb3d8bbwe!App Microsoft Wi-Fi 42 | Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge Microsoft Edge 43 | Microsoft.MicrosoftSolitaireCollection_8wekyb3d8bbwe!App Microsoft Solitaire Collection 44 | Microsoft.WindowsStore_8wekyb3d8bbwe!App Microsoft Store 45 | ``` 46 | 47 | Add or Remove TaskbarPinning of an App 48 | ```powershell 49 | # Add or Remove UWP Apps like Edge 50 | Add-TaskbarPinningApp("Microsoft Edge") 51 | Remove-TaskbarPinningApp("Microsoft Edge") 52 | ``` 53 | -------------------------------------------------------------------------------- /TaskbarPinning.ps1: -------------------------------------------------------------------------------- 1 | # --- Variant 1: Pin / Unpin regular Win32/64 Executables (no UWP Apps) not already found in Start Menu ----- 2 | Function Toggle-TaskbarPinning($PinningTarget) { 3 | # Create HKCU:\SOFTWARE\Classes\*\shell\PinMeToTaskBar" with CommandHandler "TaskbarPin" of Explorer 4 | $Key2 = (Get-Item "HKCU:\SOFTWARE\Classes").OpenSubKey("*", $true) 5 | $Key3 = $Key2.CreateSubKey("shell", $true) 6 | $Key4 = $Key3.CreateSubKey("PinMeToTaskBar", $true) 7 | 8 | # Get Explorer Command Handler for TaskbarPinning (currently with v1709 its "{90AA3A4E-1CBA-4233-B8BB-535773D48449}") 9 | $ValueData = (Get-ItemProperty ("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.taskbarpin")).ExplorerCommandHandler 10 | $Key4.SetValue("ExplorerCommandHandler", $ValueData) 11 | 12 | # execute Target-Objekts Shell-Verb "PinMeToTaskBar" (which we created just above) 13 | $Shell = New-Object -ComObject "Shell.Application" 14 | $Folder = $Shell.Namespace((Get-Item $PinningTarget).DirectoryName) 15 | $Item = $Folder.ParseName((Get-Item $PinningTarget).Name) 16 | $Item.InvokeVerb("PinMeToTaskBar") 17 | 18 | # remove the created PinMeToTaskBar entry 19 | $Key3.DeleteSubKey("PinMeToTaskBar") 20 | if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) { $Key2.DeleteSubKey("shell") } 21 | } 22 | 23 | function Get-TaskbarPinningList { 24 | $Shortcuts = Get-ChildItem -Recurse "$env:USERPROFILE\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" -Include *.lnk 25 | $Shell = New-Object -ComObject WScript.Shell 26 | foreach ($Shortcut in $Shortcuts) 27 | { 28 | $Properties = @{ 29 | ShortcutName = $Shortcut.Name; 30 | ShortcutFull = $Shortcut.FullName; 31 | ShortcutPath = $shortcut.DirectoryName 32 | Target = $Shell.CreateShortcut($Shortcut).targetpath 33 | } 34 | New-Object PSObject -Property $Properties 35 | } 36 | 37 | [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null 38 | } 39 | 40 | function Get-TaskbarPinning ($PinningTarget) { 41 | $ExistingTargets = (Get-TaskbarPinningList).Target 42 | $ExistingTargets -contains $PinningTarget 43 | } 44 | 45 | function Add-TaskbarPinning ($PinningTarget) { 46 | if (Get-TaskbarPinning($PinningTarget)) { Write-Host "Pinning for $PinningTarget already exists!" } 47 | else {Toggle-TaskbarPinning($PinningTarget)} 48 | } 49 | 50 | function Remove-TaskbarPinning ($PinningTarget) { 51 | if (Get-TaskbarPinning($PinningTarget)) { Toggle-TaskbarPinning($PinningTarget) } 52 | else { Write-Host "Pinning for $PinningTarget does not exist!" } 53 | } 54 | 55 | 56 | # --- Variant 2: Pin / Unpin Applications and UWP Apps already listed in Start Menu 57 | function getExplorerVerb([string]$verb) { 58 | $getstring = @' 59 | [DllImport("kernel32.dll", CharSet = CharSet.Auto)] 60 | public static extern IntPtr GetModuleHandle(string lpModuleName); 61 | 62 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 63 | internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax); 64 | 65 | public static string GetString(uint strId) { 66 | IntPtr intPtr = GetModuleHandle("shell32.dll"); 67 | StringBuilder sb = new StringBuilder(255); 68 | LoadString(intPtr, strId, sb, sb.Capacity); 69 | return sb.ToString(); 70 | } 71 | '@ 72 | $getstring = Add-Type $getstring -PassThru -Name GetStr -Using System.Text 73 | 74 | if ($verb -eq "PinToTaskbar") { $getstring[0]::GetString(5386) } # String: Pin to Taskbar 75 | if ($verb -eq "UnpinFromTaskbar") { $getstring[0]::GetString(5387) } # String: Unpin from taskbar 76 | if ($verb -eq "PinToStart") { $getstring[0]::GetString(51201) } # String: Pin to start 77 | if ($verb -eq "UnpinFromStart") { $getstring[0]::GetString(51394) } # String: Unpin from start 78 | } 79 | 80 | 81 | function Get-ExplorerApps([string]$AppName) { 82 | $apps = (New-Object -Com Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() 83 | $apps | Where {$_.Name -like $AppName -or $app.Path -like $AppName} 84 | } 85 | 86 | function List-ExplorerApps() { List-ExplorerApps(""); } 87 | function List-ExplorerApps([string]$AppName) { 88 | $apps = Get-ExplorerApps("*$AppName*") 89 | $AppList = @{}; 90 | foreach ($app in $apps) { $AppList.Add($app.Path, $app.Name) } 91 | $AppList | Format-Table -AutoSize 92 | } 93 | 94 | function Configure-TaskbarPinningApp([string]$AppName, [string]$Verb) { 95 | $myProcessName = Get-Process | where {$_.ID -eq $pid} | % {$_.ProcessName} 96 | if (-not ($myProcessName -like "explorer")) { Write-Host "ERROR: Configuring PinningApp can only be done by Processes named 'explorer' but current ProcessName is $myProcessName" } 97 | 98 | $apps = Get-ExplorerApps($AppName) 99 | if ($apps.Count -eq 0) { Write-Host "Error: No App with exact Path or Name '$AppName' found" } 100 | $ExplorerVerb = getExplorerVerb($Verb); 101 | foreach ($app in $apps) { 102 | $done = "False (Verb $Verb not found)" 103 | $app.Verbs() | Where {$_.Name -eq $ExplorerVerb} | ForEach {$_.DoIt(); $done=$true } 104 | Write-Host $verb $app.Name "-> Result:" $done 105 | } 106 | } 107 | 108 | function Remove-TaskbarPinningApp([string]$AppName) { Configure-TaskbarPinningApp $AppName "UnpinFromTaskbar" } 109 | function Add-TaskbarPinningApp([string]$AppName) { Configure-TaskbarPinningApp $AppName "PinToTaskbar" } 110 | 111 | 112 | 113 | # --- Examples Variant 1: Pin / Unpin regular Win32/64 Executables (no UWP Apps) not already found in Start Menu ----- 114 | 115 | ## Add Taskbar-Pinning 116 | # Add-TaskbarPinning("C:\Windows\Notepad.exe") 117 | 118 | ## Remove Taskbar-Pinning 119 | # Remove-TaskbarPinning("C:\Windows\Notepad.exe") 120 | 121 | 122 | # --- Examples Variant 2: Pin / Unpin Applications and UWP Apps already listed in Start Menu 123 | ## List all Explorer known Apps (Name and Path) 124 | # List-ExplorerApps 125 | # 126 | ## List all by Explorer known Apps containing a given Subtring 127 | # List-ExplorerApps("Edge") 128 | # 129 | ## Add or Remove UWP Apps like Edge 130 | # Add-TaskbarPinningApp("Microsoft Edge") 131 | # Remove-TaskbarPinningApp("Microsoft Edge") 132 | # 133 | # Note: Handling Add-/Remove-TaskbarPinningApp can only be done by Processes named "explorer.exe" 134 | # Workaround to do this with Powershell: Make a copy of PowerShell named explorer.exe in Temp-Directory and use this 135 | # copy $env:windir\System32\WindowsPowerShell\v1.0\powershell.exe $env:TEMP\explorer.exe 136 | --------------------------------------------------------------------------------