2

我正在尝试将程序固定到 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 磁贴。

请帮忙

4

2 回答 2

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"
于 2017-03-02T11:14:38.730 回答
0

这在 Windows 10 中不再可能(最新版本似乎在 8.1 中工作)。我不能肯定地说,但这些问题似乎是联系在一起的。请在此处查看:
https
://connect.microsoft.com/PowerShell/feedback/details/1609288/pi​​n-to-taskbar-no-longer-working-in-windows-10 以及此处:
使用 PS 将程序固定到任务栏视窗 10

于 2016-04-22T10:51:57.563 回答