Dan*_*rth 35 powershell windows-10
我正在尝试使用以下代码将程序固定到Windows 10(RTM)中的任务栏:
$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');
Run Code Online (Sandbox Code Playgroud)
这适用于Windows 8.1,但不再适用于Windows 10.
如果我执行$item.Verbs(),我得到这些:
Application Parent Name
----------- ------ ----
&Open
Run as &administrator
&Pin to Start
Restore previous &versions
Cu&t
&Copy
Create &shortcut
&Delete
Rena&me
P&roperties
Run Code Online (Sandbox Code Playgroud)
如您所见,没有动词将其固定到任务栏.但是,如果我右键单击该特定文件,则选项位于:

问题:
我错过了什么吗?
Windows 10中是否有新方法将程序固定到任务栏?
我有同样的问题,我仍然不知道如何处理它,但是这个小命令行工具可以:
http://www.technosys.net/products/utils/pintotaskbar
您可以像这样在命令行中使用它:
syspin "path/file.exe" c:5386
Run Code Online (Sandbox Code Playgroud)
将程序固定到任务栏和
syspin "path/file.exe" c:5387
Run Code Online (Sandbox Code Playgroud)
解开它。这对我来说很好用。
非常好!我对该powershell示例进行了一些小调整,希望您不要介意:)
param (
[parameter(Mandatory=$True, HelpMessage="Target item to pin")]
[ValidateNotNullOrEmpty()]
[string] $Target
)
if (!(Test-Path $Target)) {
Write-Warning "You freaking dumbass!!! $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)
}
Run Code Online (Sandbox Code Playgroud)
这是Humberto的移植到PowerShell的vbscript解决方案:
Param($Target)
$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)
}
Run Code Online (Sandbox Code Playgroud)
只是将其加粗,这样人们就不会在这里浪费时间。希望有人可以更新上面的内容(因为它们是很好的答案,但由于微软进行了更改而不再工作,所以希望对这里的答案进行一些调整可以让它们再次工作)。由于目前没有已知的方法可以使用 PowerShell 将应用程序固定到任务栏(因为此页面上的解决方案都不起作用),因此我知道唯一有效的解决方案是应用程序syspin.exe。请更新 PowerShell 答案,因为这比使用syspin. 目前(遗憾的是),此页面主要充当“美人计”;人们来到这里,很高兴找到这个问题的答案,结果却浪费了时间去尝试那些全都失效的解决方案。
很抱歉要复活这么旧的东西。
我不知道如何在Powershell中执行此操作,但是在vbscript中,您可以执行我开发的此方法。无论系统语言如何,它都可以工作。
适用于Windows 8.x和10。
脚本
If WScript.Arguments.Count < 1 Then WScript.Quit
'----------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFile = WScript.Arguments.Item(0)
sKey1 = "HKCU\Software\Classes\*\shell\{:}\\"
sKey2 = Replace(sKey1, "\\", "\ExplorerCommandHandler")
'----------------------------------------------------------------------
With WScript.CreateObject("WScript.Shell")
KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _
"\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler")
.RegWrite sKey2, KeyValue, "REG_SZ"
With WScript.CreateObject("Shell.Application")
With .Namespace(objFSO.GetParentFolderName(objFile))
With .ParseName(objFSO.GetFileName(objFile))
.InvokeVerb("{:}")
End With
End With
End With
.Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True
End With
'----------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
命令行:
pin and unpin: taskbarpin.vbs [fullpath]
Example: taskbarpin.vbs "C:\Windows\notepad.exe"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42765 次 |
| 最近记录: |