[英]powershell script creates Windows 10 notification and it disappears after popup
the following powershell script successfully creates a notification but after the little popup retracts it doesn't show on the Notification Center, any way to leave it in the notification center until the user dismisses it ? 以下powershell脚本成功创建了一个通知但是在小弹出窗口缩回之后它没有显示在Notification Center上,是否有任何方法将它留在通知中心,直到用户解除它为止?
param([String]$prodName)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
$ToastTemplate = '
<toast launch="app-defined-string">
<visual>
<binding template="ToastGeneric">
<text>'+$prodName+'</text>
</binding>
</visual>
</toast>'
Write-Output $ToastTemplate;
$currTime = (Get-Date).AddSeconds(10);
"currTime : " + $currTime
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$schedNotification = New-Object Windows.UI.Notifications.ToastNotification($xml)
$schedNotification.SuppressPopup = $True
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($prodName)
$notifier.Show($schedNotification)
$schedNotification = New-Object Windows.UI.Notifications.ScheduledToastNotification($xml, $currTime)
$notifier.AddToSchedule($schedNotification)
If you show your notification like this: 如果您显示如下通知:
CreateToastNotifier("PowerShellAppId")
Then in your "Settings \\ System \\ Notifications & Actions", there should register new app named "PowerShellAppId". 然后在“Settings \\ System \\ Notifications&Actions”中,应该注册名为“PowerShellAppId”的新应用程序。
Edit it, and select option "Show notifications in action center". 编辑它,然后选择“在操作中心显示通知”选项。 If you run your script again, message should leave in notification panel.
如果再次运行脚本,则消息应保留在通知面板中。
In your example you have $prodName
as AppID. 在您的示例中,您将
$prodName
作为AppID。 So each time, you run script with different prodName, Windows will register it as separate entry, and you will have to set registry flag ("Show notifications in action center") again. 因此,每次使用不同的prodName运行脚本时,Windows都会将其注册为单独的条目,并且您必须再次设置注册表标志(“在操作中心显示通知”)。
You can do it using PowerShell like this: 你可以使用PowerShell这样做:
Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\$prodName" -Name "ShowInActionCenter" -Type Dword -Value "1"
Consider using constant app name, something like NotificationManager to simplify things. 考虑使用常量应用程序名称,例如NotificationManager来简化操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.