2012-03-16 340 views
12

PowerShellを使用してWindows 7のタスクバーにいくつかのプログラムを固定できますか?ステップバイステップで説明してください。PowerShellを使用してタスクバーにピン留めする方法

そして、フォルダを タスクバーに固定するには、次のコードを変更する方法はありますか。例

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

このパスには、exampleという名前のフォルダがあります。

答えて

22

Shell.Application COMオブジェクトを使用してVerb(タスクバーにピン止め)を呼び出すことができます。ここではいくつかのサンプルコードです:

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

例はやや複雑です。

$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

タイプミス? –

+0

ファイルの右クリックコンテキストメニューで押すことができるホットキーに使用されているため、実際には '&'があります。 –

+0

okですが、リンク内の関数は$ verb.replace( "&"、 "")...今すぐテストすることはできません。 –

14

別の方法

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

それとも

$pn.invokeverb('taskbarunpin') 

注意の固定を解除:ここでは単純化されたバージョンであるnotepad.exeをは%windir%下ではないかもしれないが、それはサーバOSのため%windir%\system32下に存在する可能性があります。

6

私はPowerShellでこれを行う必要があったので、私はここで他の人が提供する方法を利用しました。これは私が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') 
} 

使用例:「タスマニアへピン&キロバール」や「タスクバーにピン」である上


# 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

動作しないようですOK Windows Server 2016データセンター。 – stej

関連する問題