Toast通知不适用于Windows Fall Creators Update [英] Toast notification not working on Windows fall creators update
问题描述
我有一个 PowerShell
代码,我将其称为 .NET
参考来进行敬酒通知,它在以前的更新中效果很好.但是当Windows 10 Fall Creators(FCU)更新时,它消失了,相同的代码现在不起作用:
$ app ="HTML报告"[Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications,ContentType = WindowsRuntime]$ Template = [Windows.UI.Notifications.ToastTemplateType] :: ToastImageAndText01#获取模板XML,以便我们可以操纵值[xml] $ ToastTemplate =([Windows.UI.Notifications.ToastNotificationManager] :: GetTemplateContent($ Template).GetXml())[xml] $ ToastTemplate = @< toast launch ="app-defined-string"><视觉>< binding template ="ToastGeneric">< text> DNS警报...</text>< text>我们注意到您在Wasaki附近.托马斯(Thomas)上次访问后留下了5星级的评价,您想尝试一下吗?</text></binding></visual>< actions>< action activationType ="background" content =稍后提醒我" arguments =稍后"/></actions></toast>"@$ ToastXml =新对象-TypeName Windows.Data.Xml.Dom.XmlDocument$ ToastXml.LoadXml($ ToastTemplate.OuterXml)$ notify = [Windows.UI.Notifications.ToastNotificationManager] :: CreateToastNotifier($ app)$ notify.Show($ ToastXml)
如评论中所述,最近必须在
您还可以通过注册表在 HKCU:\ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings
对于PowerShell示例,您将在以下位置添加一个名为 ShowInActionCenter
的DWORD(设置为1):
HKCU:\ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7} \ WindowsPowerShell \ v1.0 \ powershell.exe \
如果要创建自己的AppId,则需要查看如何创建 AppxManifest.xml .我仍在研究一种用户友好的方法.
I have a PowerShell
code, which I called the .NET
reference for doing the toast notification, it works good at previous update. but when got the windows 10 fall creators (FCU) update, it's gone, the same code not working now:
$app = "HTML Report"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01
#Gets the Template XML so we can manipulate the values
[xml]$ToastTemplate = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template).GetXml())
[xml]$ToastTemplate = @"
<toast launch="app-defined-string">
<visual>
<binding template="ToastGeneric">
<text>DNS Alert...</text>
<text>We noticed that you are near Wasaki. Thomas left a 5 star rating after his last visit, do you want to try it?</text>
</binding>
</visual>
<actions>
<action activationType="background" content="Remind me later" arguments="later"/>
</actions>
</toast>
"@
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)
$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)
$notify.Show($ToastXml)
As mentioned in the comments, this is something that recently had to be addressed in the BurntToast module. There's a blog post that accompanies this change too, but I'll do my best to summarize here for the completeness of this answer.
This boils down to the "Application User Model ID" (hereafter referred to as AppId), that you're providing to the Toast Notification Manager.
Strictly speaking, this AppId needs to match a an AppId embeded in a shortcut that's sitting in your Start Menu. This has always been the case, however there was a loophole of sorts that allowed any old AppId in previous versions of Windows 10.
As much as it sucks for those of us who are creating Toasts from scripts, that loophole has been closed and our AppIds, as of the Fall Creators Update, need to be "real."
You can find a list of valid AppIds by running:
Get-StartApps
I've opted to default to the one for PowerShell.exe:
{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe
It should be noted that you still need to configure some of these (including PowerShell) so that their Toasts are actually displayed in the Action Center when they time out.
You can do this via a "Settings":
Settings -> System -> Notifications & actions -> PowerShell (scroll down, you'll have needed to have sent at least one Toast for it to appear) -> Show notifications in action center.
You can also do this via the registry, under HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings
For the PowerShell example, you would add a DWORD (set to 1) called ShowInActionCenter
under:
HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe\
If you want to do your own AppId, you'll need to look at how to create a shortcut with an AppId, or creating a dummy UWP app via an AppxManifest.xml. I'm still working on a user friendly way of doing one of these.
这篇关于Toast通知不适用于Windows Fall Creators Update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!