The Taskbar is part of Windows Shell (thinking 1990s COM). It is no surprise that the code to add an application to the Taskbar requires accessing a COM object:
$shellApplication = New-Object -ComObject shell.application
$taskbarApplicaxtion = $shellApplication.Namespace($directory).ParseName($candidate.Name)
$taskbarApplicaxtion.invokeverb('taskbarpin')
The PowerShell script to add the following applications to the TaskBar is below:
- Chrome
- Edge
- Notepad++
- Visual Studio Code
- Visual Studio
- SQL Server Management Studio
The PowerShell script is as follows:
[string] $shellApplicationVerbTaskbarPin = 'taskbarpin'
function Add-TaskbarApplication() {
param (
[Parameter(Mandatory = $true)]
[string] $applicationExecutable,
[Parameter(Mandatory = $false)]
[string] $applicationCandidatePath = ${env:ProgramFiles(x86)}
)
$candidates = Get-ChildItem `
-Path $applicationCandidatePath `
-Filter $applicationExecutable `
-Recurse `
-ErrorAction SilentlyContinue `
-Force
if ($null -eq $candidates) {
# Application not found
return
}
foreach ($candidate in $candidates) {
[string] $directory = Split-Path -Path $candidate.FullName
$shellApplication = New-Object -ComObject shell.application
$taskbarApplicaxtion = $shellApplication.Namespace($directory).ParseName($candidate.Name)
if ($null -eq $taskbarApplicaxtion) {
continue
}
$taskbarApplicaxtion.invokeverb($shellApplicationVerbTaskbarPin)
break # certain files like msedge.exe are in multiple locations so only one pinning
}
}
Add-TaskbarApplication 'chrome.exe'
Add-TaskbarApplication 'msedge.exe'
Add-TaskbarApplication 'notepad++.exe'
# Visual Studio Code
Add-TaskbarApplication 'code.exe' $env:LOCALAPPDATA
# Visual Studio
Add-TaskbarApplication 'devenv.exe'
# SQL Server Management Studio
Add-TaskbarApplication 'ssms.exe'
No comments :
Post a Comment