Toast 通知不適用於 Windows 秋季創建者更新
我有一個
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模組中解決的問題。有一個部落格文章也伴隨著這個變化,但我會盡我所能在這裡總結這個答案的完整性。
這歸結為您提供給 Toast 通知管理器的“應用程序使用者模型 ID”(以下稱為 AppId)。
嚴格來說,此 AppId 需要與嵌入在您的“開始”菜單中的快捷方式中的 AppId 匹配。情況一直如此,但是在以前版本的 Windows 10 中存在允許任何舊 AppId 的各種漏洞。
儘管對於我們這些從腳本創建 Toast 的人來說很糟糕,但這個漏洞已經被堵住了,我們的 AppIds,截至秋季創作者更新,需要是“真實的”。
您可以通過執行以下命令找到有效 AppId 的列表:
Get-StartApps我選擇預設為 PowerShell.exe 的那個:
{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe
需要注意的是,您仍然需要配置其中的一些(包括 PowerShell),以便它們的 Toast 在超時時實際顯示在 Action Center 中。
您可以通過“設置”執行此操作:
設置 -> 系統 -> 通知和操作 -> PowerShell(向下滾動,您需要發送至少一個 Toast 才能顯示)-> 在操作中心顯示通知。
您也可以通過系統資料庫執行此操作,在
HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings對於 PowerShell 範例,您將添加一個 DWORD(設置為 1),呼叫
ShowInActionCenter如下:HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe\
如果您想做自己的 AppId,您需要了解如何使用 AppId 創建快捷方式,或通過AppxManifest.xml創建虛擬 UWP 應用程序。我仍在研究一種使用者友好的方式來做其中之一。
