Vì tôi cần thực hiện điều này thông qua PowerShell, tôi đã sử dụng các phương pháp được cung cấp bởi những người khác tại đây. Đây là triển khai thực hiện của tôi, tôi đã kết thúc thêm vào một module 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')
}
sử dụng Ví dụ cho một kịch bản dự phòng:
# 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
}
typo trên 'Pin to Tas & kbar' hoặc là 'Pin to Taskbar'? –
Nó thực sự có '&' vì nó được sử dụng cho phím nóng mà bạn có thể nhấn trong trình đơn ngữ cảnh nhấp chuột phải của tệp. –
ok, nhưng chức năng trong liên kết hiển thị $ verb.replace ("&", "") ... Không thể kiểm tra nó ngay bây giờ .. –