.net - Toast 通知不适用于 Windows 秋季创作者更新

标签 .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)

最佳答案

如评论中所述,这是最近必须在 BurntToast 中解决的问题模块。有一个 blog post这也伴随着这个变化,但为了这个答案的完整性,我会尽我所能在这里总结一下。

这归结为您提供给 Toast 通知管理器的“应用程序用户模型 ID”(以下称为 AppId)。

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

对于我们这些从脚本创建 Toasts 的人来说,这个漏洞已经被堵上了,我们的 AppIds,从 Fall Creators Update 开始,需要是“真实的”。

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

Get-StartApps

我选择默认使用 PowerShell.exe:

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

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

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

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

PowerShell notification settings

您也可以通过注册表执行此操作,位于 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,你需要看看如何创建一个 shortcut with an AppId ,或通过 AppxManifest.xml 创建虚拟 UWP 应用程序.我仍在研究一种用户友好的方式来执行其中的一项操作。

关于.net - Toast 通知不适用于 Windows 秋季创作者更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46814858/

相关文章:

c# - 如果特定应用程序打开和关闭,如何触发启动我的 Windows 服务应用程序?

.net - 多 View 控件如何处理其 View 状态?

c# - 你如何获得默认用户文件夹(例如 c :\users\Default)

python - 在 Windows 中以管理员身份运行 python 脚本

windows - npapi 插件如何从浏览器获取 WM_ACTIVATE 消息?

powershell - 在 PowerShell 中将路径设置为变量

json - 我想使用powershell将convert.d csv加载到json文件文档以进行elasticsearch

windows - Powershell - 为特定用户设置桌面背景(Windows 7 和/或 2008 Server)

c# - 如何绘制圆角矩形作为圆角窗体的边框?

windows - 适用于 Windows 的最佳 CVS 客户端是什么?