cet*_*int 18 powershell taskbar windows-7
如何使用PowerShell将某些程序固定到Windows 7上的任务栏?请逐步解释.
以及如何修改以下代码将文件夹固定到任务栏?例如
$folder = $shell.Namespace('D:\Work')
Run Code Online (Sandbox Code Playgroud)
在此路径中,example命名文件夹.
And*_*ndi 22
您可以Verb使用Shell.Application COM对象调用(Pin to Taskbar).这是一些示例代码:
http://gallery.technet.microsoft.com/scriptcenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750
这个例子有点复杂.这是一个简化版本:
$shell = new-object -com "Shell.Application"
$folder = $shell.Namespace('C:\Windows')
$item = $folder.Parsename('notepad.exe')
$verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
if ($verb) {$verb.DoIt()}
Run Code Online (Sandbox Code Playgroud)
小智 18
其他方式
$sa = new-object -c shell.application
$pn = $sa.namespace($env:windir).parsename('notepad.exe')
$pn.invokeverb('taskbarpin')
Run Code Online (Sandbox Code Playgroud)
或取消固定
$pn.invokeverb('taskbarunpin')
Run Code Online (Sandbox Code Playgroud)
注意:notepad.exe可能不在%windir%,它可能存在%windir%\system32于服务器操作系统下.
由于我需要通过PowerShell执行此操作,因此我使用了其他人提供的方法.这是我的实现我最终添加到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')
}
Run Code Online (Sandbox Code Playgroud)
# 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28985 次 |
| 最近记录: |