ToastNotifications sent from PowerShell disappear from Action Center

☆樱花仙子☆ 提交于 2019-11-29 01:01:31

问题


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)

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?


回答1:


You must set a registry key for each AppID whose notifications you would like to persist in the Action Center.

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.

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.



来源:https://stackoverflow.com/questions/31772192/toastnotifications-sent-from-powershell-disappear-from-action-center

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!