简体   繁体   English

取消固定 Microsoft Edge 并以编程方式存储任务栏快捷方式

[英]Unpin the Microsoft Edge and store taskbar shortcuts programmatically

I setup computers daily and I need to remove the Microsoft Edge and Store taskbar shortcuts.我每天都设置计算机,我需要删除 Microsoft Edge 和 Store 任务栏快捷方式。

I am having trouble creating a script and I have searched for other stackoverflow posts but they were not helpful to me.我在创建脚本时遇到问题,我搜索了其他 stackoverflow 帖子,但它们对我没有帮助。

Does anyone have a script that can unpin the MS Edge and Store taskbar shortcuts?有没有人有可以取消固定 MS Edge 和 Store 任务栏快捷方式的脚本?

You can unpin taskbar items by running the following PowerShell commands.您可以通过运行以下 PowerShell 命令取消固定任务栏项目。

function Unpin-App([string]$appname) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
        ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt()}
}

Unpin-App("Microsoft Edge")
Unpin-App("Microsoft Store")

This should work for any application on the taskbar.这应该适用于任务栏上的任何应用程序。 If the application isn't found, the error InvokeMethodOnNull will be thrown.如果未找到该应用程序,将抛出错误InvokeMethodOnNull

What this does:这是做什么的:

  • Enumerates the Shell/taskbar COM object namespace枚举 Shell/taskbar COM 对象命名空间
  • Matches the item with the name $appname (in this case, Edge and Store)匹配名称$appname的项目(在本例中为 Edge 和 Store)
  • Gets the verb Unpin from taskbar of that com object Unpin from taskbar
  • Executes the verb to remove it from the taskbar (without having to kill explorer.exe)执行动词以将其从任务栏中删除(无需终止 explorer.exe)

Very nice solution from Judge2020, +1来自 Judge2020 的非常好的解决方案,+1

  • With a RegEx and -match instead of -eq you can unpin several Apps in one run使用 RegEx 和 -match 而不是 -eq,您可以在一次运行中取消固定多个应用程序
  • The unpin verbs are localized, in German it's Von "Start" lösen unpin 动词是本地化的,在德语中是Von "Start" lösen

$appnames = "^Microsoft Edge$|^Store$"
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | 
  Where-Object{$_.Name -match $appnames}).Verbs() | 
  Where-Object{$_.Name.replace('&','') -match 'Unpin from taskbar|Von "Start" lösen'} | 
  ForEach-Object{$_.DoIt(); $exec = $true}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM