7

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)
Aso
  • 603
  • 7
  • 16
  • 2
    The [burnttoast module](https://github.com/Windos/BurntToast) has some notes about 1709 and changes with regard to AppIDs. Here's the [GitHub commit](https://github.com/Windos/BurntToast/commit/674b80c9fbbd689a729c1fd2c3dedd386843a5a4) with the changes they made, hopefully that helps. – BenH Oct 18 '17 at 17:55
  • I'm using my own code, he spoke him code – Aso Oct 18 '17 at 17:57

1 Answers1

15

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.

Windos
  • 1,796
  • 1
  • 13
  • 19
  • thank you Mr. Windos. I appreciate your answer. but still not working for me. in my 'Notifications & actions' `PowerShell` doesn't exist. also I created those registry {Keys, Values}. please check my code in your desktop. – Aso Oct 18 '17 at 19:58
  • 1
    @Aso, when I change the first line of your code to `$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'` it's working for me. – Windos Oct 18 '17 at 20:05
  • Sorry Mr. @Winos, can i change the `Windows PowerShell` in toast appear, please? see what i mean: http://up.h4kurd.com/files/59e9876ed3309.png – Aso Oct 20 '17 at 05:19
  • @Windos have you found any way to show toasts without having a real AppID? – Jonathan Beaudoin Nov 02 '17 at 02:58
  • 2
    @JonathanBeaudoin Nothing that I'm happy with, the best I've managed to do is turn on developer mode and register a dummy appx manifest... I'll be doing a write up on that just in case people do want to do that. – Windos Nov 02 '17 at 03:00
  • Can you please explain more on how to create this shortcut? The code in the link in c++. Should i run it for every user that install the app? Will I execute it as separate script after installing the app? The other method is also interesting. So i just need to create this manifest file and put it in the root of the project? – Ali123 Jan 23 '21 at 22:05
  • I've never had much luck using the C# code, @Ali123. I ended up using WiX: https://toastit.dev/2018/02/04/burnttoast-appid-installer/ https://toastit.dev/2018/03/03/burnttoast-wix/ That's a little heavy, I know. I also had luck using Adam Driscoll's UDForge module, but I haven't written that up yet. https://github.com/ironmansoftware/ud-forge – Windos Jan 31 '21 at 19:45
  • @Windos, Thanks for sharing, will check out Wix even if i don't like the dependency. For the second link, it's in Electron JS which is a different framework entirely. I tried it before and it's working even for the mac but i didn't test custom notifications. The problem with Node based projects is that most packages are outdated and not well documented or maintained. – Ali123 Feb 01 '21 at 06:45