Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pin to taskbar using PowerShell

How can I pin some programs to taskbar on Windows 7 using PowerShell? Please explain step-by-step.

And How to modify the following code to pin a folder to taskbar? For Example

$folder = $shell.Namespace('D:\Work') 

In this path, example named folder.

like image 339
cethint Avatar asked Mar 16 '12 15:03

cethint


People also ask

How do I permanently Pin to taskbar?

First, launch the program as you normally would. At the bottom of your screen, the program icon appears on the taskbar. Right-click it and, from the menu, select Pin to taskbar. The icon is pinned permanently to the taskbar.

Can you Pin power to taskbar?

There is no option to pin the Power setting to taskbar, but as a workaround you may create a shortcut for 'Shutdown' and 'Restart' and pin the shortcut to taskbar.


2 Answers

You can invoke a Verb (Pin to Taskbar) using the Shell.Application COM object. Here's some example code:

http://gallery.technet.microsoft.com/scriptcenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750

The example is somewhat complicated. Here is a simplified version:

$shell = new-object -com "Shell.Application"   $folder = $shell.Namespace('C:\Windows')     $item = $folder.Parsename('notepad.exe') $verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'} if ($verb) {$verb.DoIt()} 
like image 195
Andy Arismendi Avatar answered Sep 29 '22 11:09

Andy Arismendi


Another way

$sa = new-object -c shell.application
$pn = $sa.namespace($env:windir).parsename('notepad.exe')
$pn.invokeverb('taskbarpin')

Or unpin

$pn.invokeverb('taskbarunpin')

Note: notepad.exe may not be under %windir%, it may exist under %windir%\system32 for server OS's.

like image 43
Zombo Avatar answered Sep 29 '22 12:09

Zombo