在 Windows 10 中使用 PS 将程序固定到任务栏 [英] Pin program to taskbar using PS in Windows 10

查看:72
本文介绍了在 Windows 10 中使用 PS 将程序固定到任务栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码将程序固定到 Windows 10 (RTM) 中的任务栏:

I am trying to pin a program to the taskbar in Windows 10 (RTM) using this code:

$shell = new-object -com "Shell.Application"  
$folder = $shell.Namespace((Join-Path $env:SystemRoot System32\WindowsPowerShell\v1.0))
$item = $folder.Parsename('powershell_ise.exe')
$item.invokeverb('taskbarpin');

这适用于 Windows 8.1,但不再适用于 Windows 10.

This worked on Windows 8.1, but no longer works on Windows 10.

如果我执行 $item.Verbs(),我得到这些:

If I execute $item.Verbs(), I get these:

Application Parent Name
----------- ------ ----
                   &Open
                   Run as &administrator
                   &Pin to Start

                   Restore previous &versions

                   Cu&t
                   &Copy
                   Create &shortcut
                   &Delete
                   Rena&me
                   P&roperties

如您所见,没有将其固定到任务栏的动词.但是,如果我右键单击该特定文件,则会出现以下选项:

As you can see, there is no verb for pinning it to the taskbar. If I right click that specific file, however, the option is there:

问题:
我错过了什么吗?
Windows 10 中是否有将程序固定到任务栏的新方法?

Questions:
Am I missing something?
Is there a new way in Windows 10 to pin a program to the taskbar?

推荐答案

非常好!我对那个 powershell 示例做了一些小的调整,希望你不介意:)

Very nice! I made a few small tweaks to that powershell example, I hope you don't mind :)

param (
    [parameter(Mandatory=$True, HelpMessage="Target item to pin")]
    [ValidateNotNullOrEmpty()]
    [string] $Target
)
if (!(Test-Path $Target)) {
    Write-Warning "$Target does not exist"
    break
}

$KeyPath1  = "HKCU:\SOFTWARE\Classes"
$KeyPath2  = "*"
$KeyPath3  = "shell"
$KeyPath4  = "{:}"
$ValueName = "ExplorerCommandHandler"
$ValueData =
    (Get-ItemProperty `
        ("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\" + `
            "CommandStore\shell\Windows.taskbarpin")
    ).ExplorerCommandHandler

$Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true)
$Key3 = $Key2.CreateSubKey($KeyPath3, $true)
$Key4 = $Key3.CreateSubKey($KeyPath4, $true)
$Key4.SetValue($ValueName, $ValueData)

$Shell = New-Object -ComObject "Shell.Application"
$Folder = $Shell.Namespace((Get-Item $Target).DirectoryName)
$Item = $Folder.ParseName((Get-Item $Target).Name)
$Item.InvokeVerb("{:}")

$Key3.DeleteSubKey($KeyPath4)
if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) {
    $Key2.DeleteSubKey($KeyPath3)
}

这篇关于在 Windows 10 中使用 PS 将程序固定到任务栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆