2012-03-16 2 views
12

PowerShell을 사용하여 Windows 7의 일부 작업 표시 줄을 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

오타 나입니다 '핀을 TAS & kbar에'핀 작업 표시 줄 '이 내가 PowerShell을 모듈에 추가 결국 내 구현? –

+0

파일의 오른쪽 클릭 컨텍스트 메뉴에서 누를 수있는 바로 가기 키에 사용되기 때문에 실제로 '&'가 있습니다. –

+0

괜찮지 만 링크의 함수는 $ 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%에서하지 않을 수 있습니다, 그것은 서버 운영 체제의 대한 %windir%\system32 아래에있을 수 있습니다 .

6

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

작동하지 않는 것 같아요. 확인 Windows Server 2016 데이터 센터. – stej

관련 문제