Symantec Management Platform (SMP) Community

 View Only

Windows 10 Toast Notifications  

Mar 01, 2016 12:39 PM

Introducing Windows Toast Notifications

With the introduction of Windows 8 we were given a new way of creating notifications as part of Microsoft's Action Centre. These notifications allow Windows applications to display modern, unobtrusive notifications that are uniform in their design regardless of the invoking application. In this article I'm going to show you how you can deliver these notifcations with Altiris and how you can incorporate them into your own Altiris jobs.

Comparison

VB Message Box Windows 10 Toast Notifications
Started-VB.PNG Started-PS.PNG
Completed-VB.PNG Complete-PS.PNG

Windows Action Center

Action Centre is a centralized hub for all your notifications and alerts and provides a means of viewing past notifications. Each notification can specify an application ID which allows notifications to grouped. In the image below I have specified the application ID as "Altiris".

ActionCenter.png

Notification Powershell Script

Since the Symantec Management Agent now supports Windows 8 and Windows 10, we can now take advantage of these notifications and incorporate them into our own jobs and tasks.

These notifications are part of an API available in the .NET Framework which can be consumed by a simple Powershell script and pushed via the SMP to client's agents.

Create a new Powershell task in Altiris with the following content.

#
# Variables Defined in Altiris Task
#
$line1 = "%!Line1!%"
$line2 = "%!Line2!%"
$line3 = "%!Line3!%"

#$image must be a local file on the client's machine
$image = "%!Image!%" 
#$app is Action Center's Application ID
$app = "Altiris"

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]

# 
# Load the Notification Template - ToastTemplateType enumeration see https://msdn.microsoft.com/EN-US/library/windows/apps/windows.ui.notifications.toasttemplatetype.aspx
# 
# ToastImageAndText01
# ToastImageAndText02
# ToastImageAndText03
# ToastImageAndText04
# ToastText01
# ToastText02
# ToastText03
# ToastText04

$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())

$TextElements = $ToastTemplate.GetElementsByTagName('text')
foreach ($TextElement in $TextElements)
{
    switch ($TextElement.id)
    {
        '1' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line1)) }
        '2' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line2)) }
        '3' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line3)) }
    }
}

#
# If the template requires an image, assign one.
#
if ($Template -like '*Image*')
{

    $ImageElements = $ToastTemplate.GetElementsByTagName('image')
    $ImageElements[0].src = "file:///$image"

}

           
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)

$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)

$notify.Show($ToastXml)

Before you can run Powershell scripts on a client you either have to sign them or change the restriction policy. The latter is a lot easier to setup and Altiris give us two built in tasks to do this.

  1. Disable Powershell Signing Policy - A Command Script which runs powershell Set-Executionpolicy unrestricted
  2. Enable Powershell Signing Policy - A Command Script which runs powershell Set-Executionpolicy restricted

Below is an example of how you can include the signing tasks and the notification task into an existing job. As you can see, the notification parameters can also be defined here.

Altiris Task Notify2.PNG

I hope you find this useful.

Statistics
0 Favorited
5 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Jan 22, 2019 11:42 AM

Hi Mikkel.P.Jensen

To make this work in Windows 10 v1803 and 1809 you have to specify a valid AppID.

You could find a list of valid AppID´s on your Computer using Powershell with the following command: get-startapps

This command will return a list of valid AppID´s for example:

Name                       AppID
VLC media player          {6D809377-6AF0-444B-8957-A3773F02200E}\VideoLAN\VLC\vlc.exe

Instead of using "Altiris" as AppID use one that will show up with the "get-startapps" command

Modify the powershell script like in this exmple. Change your the variable $app = ' with something you could find when running "get-startapps" '.

The only thing I´ve modified here is the variable $app and the variable $line1 to test this in powershell....

#
# Variables Defined in Altiris Task
#
$line1 = "DEMO"
$line2 = "%!Line2!%"
$line3 = "%!Line3!%"

#$image must be a local file on the client's machine
$image = "%!Image!%" 
#$app is Action Center's Application ID
$app = '{6D809377-6AF0-444B-8957-A3773F02200E}\VideoLAN\VLC\vlc.exe'

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]

# 
# Load the Notification Template - ToastTemplateType enumeration see https://msdn.microsoft.com/EN-US/library/windows/a...
# 
# ToastImageAndText01
# ToastImageAndText02
# ToastImageAndText03
# ToastImageAndText04
# ToastText01
# ToastText02
# ToastText03
# ToastText04

$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())

$TextElements = $ToastTemplate.GetElementsByTagName('text')
foreach ($TextElement in $TextElements)
{
    switch ($TextElement.id)
    {
        '1' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line1)) }
        '2' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line2)) }
        '3' { $null = $TextElement.AppendChild($ToastTemplate.CreateTextNode($line3)) }
    }
}

#
# If the template requires an image, assign one.
#
if ($Template -like '*Image*')
{

    $ImageElements = $ToastTemplate.GetElementsByTagName('image')
    $ImageElements[0].src = "file:///$image"

}

           
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)

$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)

$notify.Show($ToastXml)

How this works!!

Network23

Jan 18, 2019 09:32 AM

I was thrilled to find this post, but unfortunately I cant make it work on Windows 10 v1803 and v1809.

On v1607 I could make it show only line1 and the image. For a few seconds only. 

Any ways to make it work on newer Win10 versions?

And how about control of the duration and maybe the snooze / dismiss option?

Thanks. 

Jul 25, 2016 01:07 PM

Very interesting. It has a great potential in Windows 10.

Related Entries and Links

No Related Resource entered.