From a55d2aa6247519984c4627ce6396f45ab4b138ae Mon Sep 17 00:00:00 2001 From: Ben Whitmore Date: Wed, 30 Dec 2020 14:22:24 +0000 Subject: [PATCH] Added a Snooze switch Added a SNooze switch to allow users to Snooze the toast. Default snooze timer is set to 1min but can be changed in the XML Section of Toast_Notify.ps1 line 190 Also fixed an error in resolving the logged on user --- CustomMessage.xml | 1 + Toast_Notify.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CustomMessage.xml b/CustomMessage.xml index 1b39fe2..809f1be 100644 --- a/CustomMessage.xml +++ b/CustomMessage.xml @@ -6,4 +6,5 @@ We are currently experiencing problems with all our systems. We are drinking coffee will provide an update shortly. Thank you for your patience Details https://byteben.com + Snooze \ No newline at end of file diff --git a/Toast_Notify.ps1 b/Toast_Notify.ps1 index eb1c2f6..b3016c0 100644 --- a/Toast_Notify.ps1 +++ b/Toast_Notify.ps1 @@ -36,6 +36,7 @@ Toast_Notify.ps1 Param ( [Parameter(Mandatory = $False)] + [Switch]$Snooze, [String]$XMLScriptDirSource = "CustomMessage.xml", [String]$XMLOtherSource @@ -82,6 +83,7 @@ If ($XMLValid -eq $True) { $EventText = $XMLToast.ToastContent.EventText $ButtonTitle = $XMLToast.ToastContent.ButtonTitle $ButtonAction = $XMLToast.ToastContent.ButtonAction + $SnoozeTitle = $XMLToast.ToastContent.SnoozeTitle #ToastDuration: Short = 7s, Long = 25s $ToastDuration = "long" @@ -99,7 +101,7 @@ If ($XMLValid -eq $True) { $Launcherid = "MSEdge" #Get last(current) logged on user - $LoggedOnUserPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" + $LoggedOnUserPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnDisplayName" If (!(Test-Path $LoggedOnUserPath)) { Try { $Firstname = $Null @@ -127,8 +129,10 @@ If ($XMLValid -eq $True) { [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null - #Build XML Template - [xml]$ToastTemplate = @" + If (!$Snooze) { + + #Build XML Template when Snooze Timer is not specified + [xml]$ToastTemplate = @" @@ -156,7 +160,47 @@ If ($XMLValid -eq $True) { "@ + } + else { + #Build XML Template when Snooze Timer is specified + [xml]$ToastTemplate = @" + + + + $CustomHello + $ToastTitle + $Signature + + + + + $EventTitle + + + + + $EventText + + + + + +"@ + } #Prepare XML $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New() $ToastXml.LoadXml($ToastTemplate.OuterXml)