在Windows 10中使用PS将程序固定到开始菜单

时间:2016-04-22 10:27:52

标签: powershell windows-10 tile startmenu

我正在尝试将程序固定到Windows 10中的开始菜单

$shell = New-Object -ComObject "Shell.Application"
$Folder = $shell.NameSpace("C:\Test")
$exe = $Folder.ParseName("notepad.exe")
#$exe.Verbs()
$ItemVerbs = $exe.Verbs()

Foreach($ItemVerb in $ItemVerbs)
{
    If($ItemVerb.Name.Replace("&","") -match "Pin to Start")
    {
       $ItemVerb.DoIt()

       Write-Host "Pin to the Start menu sucessfully.+ ""$ItermVerbTxt"" " -ForegroundColor Green
     }
}

执行此代码后,我看到成功消息,这意味着它正在找到所需的动词。

但我不想在“开始”菜单中看到notepad.exe磁贴。

请帮忙

2 个答案:

答案 0 :(得分:2)

function Pin-App { param(
[string]$appname,
[switch]$unpin
)
try{
if ($unpin.IsPresent){
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'From "Start" UnPin|Unpin from Start'} | %{$_.DoIt()}
return "App '$appname' unpinned from Start"
}else{
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'To "Start" Pin|Pin to Start'} | %{$_.DoIt()}
return "App '$appname' pinned to Start"
}
}catch{
Write-Error "Error Pinning/Unpinning App! (App-Name correct?)"
}
}

Pin-App "Outlook 2016"
Pin-App "Google Chrome" 
Pin-App "This PC"

答案 1 :(得分:0)

在Windows 10中不再可能(最新似乎在8.1中有效)。我不能肯定地说,但这些问题似乎有关。 请看这里:
https://connect.microsoft.com/PowerShell/feedback/details/1609288/pin-to-taskbar-no-longer-working-in-windows-10
还有这里:
Pin program to taskbar using PS in Windows 10