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

时间:2017-10-18 16:23:16

标签: .net windows powershell

我有一个PowerShell代码,我将.NET引用称为执行Toast通知,它在之前的更新中效果很好。但是当Windows 10的创建者(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)

1 个答案:

答案 0 :(得分:12)

正如评论中所提到的,最近必须在BurntToast模块中解决这个问题。这个变化伴随着blog post,但我会尽力总结这个答案的完整性。

这归结为&#34;应用程序用户模型ID&#34;您(以下简称AppId),您正在向Toast Notification Manager提供。

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

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

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

Get-StartApps

我选择默认使用PowerShell.exe:

  

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

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

您可以通过&#34;设置&#34;:

执行此操作

设置 - &gt;系统 - &gt;通知&amp;行动 - &gt; PowerShell(向下滚动,您需要至少发送一个Toast才能显示) - &gt;在行动中心显示通知。

PowerShell notification settings

您也可以通过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,则需要了解如何创建shortcut with an AppId或通过AppxManifest.xml创建虚拟UWP应用。我仍在以用户友好的方式开展其中一项工作。

相关问题