从PowerShell发送的ToastNotifications从Action Center中消失

syn*_*pse 9 powershell toast

我正在使用此代码从PowerShell脚本发送通知.PowerShell本身是由(持久的)Java应用程序启动的.

[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)
Run Code Online (Sandbox Code Playgroud)

它们会弹出屏幕,在操作中心可见,但很快就会消失.XAML应用程序使用相同代码发送的通知会在那里停留相当长的一段时间.有没有办法改变通过脚本发送的通知的行为?

ala*_*ran 7

您必须为AppID要在操作中心中保留其通知的每个人设置一个注册表项.

例如,如果您希望irssi通知保持不变,请添加密钥:HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\irssi使用ShowInActionCenter以值命名的DWORD 1.

感谢本文评论中的解决方案"Passing By" 和Mattias Fors创建文章.

更新:您还可以在每个应用的"通知和操作"设置中切换此设置.