Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast notification not working on Windows fall creators update

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)
like image 216
Aso Avatar asked Oct 18 '17 16:10

Aso


1 Answers

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.

PowerShell notification settings

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.

like image 168
Windos Avatar answered Sep 25 '22 22:09

Windos