我正在尝试将程序固定到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磁贴。
请帮忙
最佳答案
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"
关于powershell - 在Windows 10中使用PS将程序固定到开始菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36791289/