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

标签 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)

它们会在屏幕上弹出,并在“操作中心”中可见一会儿,但很快就会消失。 XAML应用发送的具有相同代码的通知会在此处停留相当长的时间。有没有办法更改通过脚本发送的通知的行为?

最佳答案

您必须为每个AppID设置一个注册表项,您希望将其通知保留在Action Center中。

例如,如果要保留irssi通知,请添加键:带有名为HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\irssi的DWORD的ShowInActionCenter,值为1

感谢this article's注释中的“传递”解决方案,以及Mattias Fors的创建文章。

更新:您也可以按应用在“通知和操作”设置中进行切换。

关于powershell - 从PowerShell发送的ToastNotifications从Action Center中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31772192/

相关文章:

Powershell (PS2) 记录删除项目

powershell - 通过Shell.Application调用多个文件上的动词

node.js - 使用字符串文字有效,但作为参数传递无效

android - 如何将 Toast 放入服务的 Runnable 中?

C# 控制台 Toast 停止显示通知

c# - 使用 C# 执行 Powershell commandlet 时出错

powershell - Azure 资源管理器虚拟机状态

c# - Toast 通知和地理围栏 Windows Phone 8.1

android sqlite按钮不可点击

android - 删除线程 Toast 消息