简体   繁体   English

powershell脚本创建Windows 10通知,弹出后它会消失

[英]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.

相关问题 Powershell脚本禁用所有Windows 10通知? - Powershell script to disable all Windows 10 Notifications? Powershell 脚本停止/启动 IIS 在 Windows 10 - Powershell Script to stop/start IIS in Windows 10 Powershell 脚本在 Windows 中激活 HDR 10 - Powershell script to activate HDR in Windows 10 Powershell:是否有编程方法来确定 Windows 10 上是否启用了通知? - Powershell: Is there a programmatic way to determine is Notification is enabled on Windows 10? PowerShell脚本可在Windows 10中运行,但不能在Windows Embedded Standard中运行 - PowerShell Script works in Windows 10 but not on Windows Embedded Standard 通过 powershell 脚本执行 docker run (Windows 10) - Execute docker run through powershell script (Windows 10) 来自 Windows 10 任务调度程序的 Powershell 脚本未启动 Chrome - Powershell script from Windows 10 task scheduler not launching Chrome 使用 powershell 脚本将 RSAT 安装到具有提升权限的 Windows 10 - Install RSAT using powershell script to windows 10 with elevated privileges 使用 powershell 脚本自动启用 Windows 10 触摸键盘和全键盘 - Automatically enable Windows 10 touch keyboard & full keyboard with powershell script pygame的。 Windows10。使用ProcessPoolExecutor在loop.run_in_executor之后创建其他窗口。 - Pygame. Windows 10. Creates additional windows after loop.run_in_executor using ProcessPoolExecutor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM