从 PowerShell 发送的 ToastNotifications 从操作中心消失 [英] ToastNotifications sent from PowerShell disappear from Action Center
问题描述
我正在使用此代码从 PowerShell 脚本发送通知.PowerShell 本身由(持久性)Java 应用程序启动.
I'm using this code to send notifications from PowerShell script. PowerShell itself is launched by (persistent) Java application.
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$template = "<toast><visual><binding template=`"ToastText02`"><text id=`"1`">Title</text><text id=`"2`">Test results</text></binding></visual></toast>"
$xml.LoadXml($template)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("sbt").Show($toast)
它们会在屏幕上弹出并在操作中心中可见,但很快就会消失.XAML 应用程序发送的具有相同代码的通知会在那里停留一段时间.有没有办法改变通过脚本发送的通知的行为?
They pop up on the screen and are visible in Action Center for while but quickly disappear. Notifications sent by the XAML app with the same code stay there for quite some time. Is there a way to change behavior of notifications sent via script?
推荐答案
您必须为每个 AppID
设置一个注册表项,您希望在操作中心保留其通知.
You must set a registry key for each AppID
whose notifications you would like to persist in the Action Center.
例如,如果您希望 irssi
通知持续存在,请添加密钥:HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\irssi
名为 ShowInActionCenter
的 DWORD,值为 1
.
For example, if you want your irssi
notifications to persist, add the key: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\irssi
with a DWORD named ShowInActionCenter
with value 1
.
感谢Passing By"在 这篇文章的评论,以及创建这篇文章的 Mattias Fors.
Thanks to "Passing By" for the solution in this article's comments, and Mattias Fors for creating the article.
更新:您还可以在通知和操作"设置中针对每个应用进行切换.
Update: You can also toggle this in your "Notifications & actions" Settings on a per-app basis.
这篇关于从 PowerShell 发送的 ToastNotifications 从操作中心消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!