2012-03-16 16 views
12

¿Cómo puedo anclar algunos programas a la barra de tareas en Windows 7 usando PowerShell? Por favor explique paso a paso.Cómo anclar a la barra de tareas mediante PowerShell

Y cómo modificar el siguiente código para fijar una carpeta a barra de tareas? Por ejemplo

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

En esta ruta, example carpeta con nombre.

Respuesta

22

Puede invocar un Verb (Pin en la barra de tareas) utilizando el objeto COM Shell.Application. Aquí hay un código de ejemplo:

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

El ejemplo es algo complicado. He aquí una versión simplificada:

$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()} 
+0

error tipográfico en 'Pin a Tas y kbar' o es 'Pin a la barra de tareas'? –

+0

En realidad tiene el 'y' porque se usa para la tecla rápida que puede presionar en el menú contextual del archivo al hacer clic con el botón derecho. –

+0

bien, pero las funciones en el enlace muestran un $ verb.replace ("&", "") ... No puedo probarlo ahora ... –

14

Otra forma

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

o liberar

$pn.invokeverb('taskbarunpin') 

Nota: notepad.exe puede no estar bajo %windir%, que pueda existir con arreglo %windir%\system32 para servidores de OS .

6

Como necesitaba hacer esto a través de PowerShell, utilicé los métodos proporcionados por otros aquí. Este es mi aplicación acabé añadiendo a un módulo de PowerShell:


function Get-ComFolderItem() { 
    [CMDLetBinding()] 
    param(
     [Parameter(Mandatory=$true)] $Path 
    ) 

    $ShellApp = New-Object -ComObject 'Shell.Application' 

    $Item = Get-Item $Path -ErrorAction Stop 

    if ($Item -is [System.IO.FileInfo]) { 
     $ComFolderItem = $ShellApp.Namespace($Item.Directory.FullName).ParseName($Item.Name) 
    } elseif ($Item -is [System.IO.DirectoryInfo]) { 
     $ComFolderItem = $ShellApp.Namespace($Item.Parent.FullName).ParseName($Item.Name) 
    } else { 
     throw "Path is not a file nor a directory" 
    } 

    return $ComFolderItem 
} 

function Install-TaskBarPinnedItem() { 
    [CMDLetBinding()] 
    param(
     [Parameter(Mandatory=$true)] [System.IO.FileInfo] $Item 
    ) 

    $Pinned = Get-ComFolderItem -Path $Item 

    $Pinned.invokeverb('taskbarpin') 
} 

function Uninstall-TaskBarPinnedItem() { 
    [CMDLetBinding()] 
    param(
     [Parameter(Mandatory=$true)] [System.IO.FileInfo] $Item 
    ) 

    $Pinned = Get-ComFolderItem -Path $Item 

    $Pinned.invokeverb('taskbarunpin') 
} 

Ejemplo de uso de un script de aprovisionamiento:


# The order results in a left to right ordering 
$PinnedItems = @(
    'C:\Program Files\Oracle\VirtualBox\VirtualBox.exe' 
    'C:\Program Files (x86)\Mozilla Firefox\firefox.exe' 
) 

# Removing each item and adding it again results in an idempotent ordering 
# of the items. If order doesn't matter, there is no need to uninstall the 
# item first. 
foreach($Item in $PinnedItems) { 
    Uninstall-TaskBarPinnedItem -Item $Item 
    Install-TaskBarPinnedItem -Item $Item 
} 
+0

Parece que no funciona ok Win Server 2016 DataCenter. – stej

Cuestiones relacionadas