Toast通知无法在Windows下创建者更新

Aso*_*Aso 4 .net windows powershell

我有一个PowerShell代码,我称之为.NET做吐司通知的参考,它在以前的更新中很好用.但是当得到windows 10 fall创建者(FCU)更新时,它已经消失了,相同的代码现在不能正常工作:

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

Win*_*dos 12

正如评论中所提到的,最近必须在BurntToast模块中解决这个问题.还有一篇博客文章也伴随着这一变化,但我会尽力总结这里的答案的完整性.

这归结为您提供给Toast Notification Manager的"应用程序用户模型ID"(以下简称AppId).

严格来说,此AppId需要匹配嵌入在"开始"菜单中的快捷方式中的AppId.一直都是这种情况,但是在以前版本的Windows 10中存在允许任何旧AppId的各种漏洞.

对于我们这些从脚本创建Toasts的人来说,这个漏洞已经被关闭了,而且我们的AppIds,就像Fall Creators Update一样,需要"真实".

您可以通过运行找到有效AppIds的列表:

Get-StartApps
Run Code Online (Sandbox Code Playgroud)

我选择默认使用PowerShell.exe:

{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\V1.0\powershell.exe

应该注意的是,您仍然需要配置其中一些(包括PowerShell),以便它们的Toast在超时时实际显示在Action Center中.

您可以通过"设置"执行此操作:

设置 - >系统 - >通知和操作 - > PowerShell(向下滚动,您需要至少发送一个Toast才能显示) - >在操作中心显示通知.

PowerShell通知设置

您也可以通过注册表进行此操作 HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings

对于PowerShell示例,您将添加一个ShowInActionCenter在下面调用的DWORD(设置为1):

HKCU:\ SOFTWARE \微软\的Windows\CurrentVersion \通知\设置{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\V1.0\powershell.exe \

如果您想自己创建AppId,您需要了解如何使用AppId创建快捷方式,或通过AppxManifest.xml创建虚拟UWP应用程序.我仍在以用户友好的方式开展其中一项工作.

  • @JonathanBeaudoin 没有什么让我满意的,我设法做的最好的事情就是打开开发人员模式并注册一个虚拟的 appx 清单......我会写一篇文章以防万一人们确实想要这样做那。 (2认同)