Skip to content

Instantly share code, notes, and snippets.

@Windos
Created March 31, 2020 07:16
Show Gist options
  • Save Windos/78ed980d926c634d0acede61e44a29af to your computer and use it in GitHub Desktop.
Save Windos/78ed980d926c634d0acede61e44a29af to your computer and use it in GitHub Desktop.
Example of trying to register a Windows RT event via PowerShell, specifically here we're looking at events on Toast Notifications
$XmlString = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Default Notification</text>
<image src="C:\Program Files\PowerShell\7\assets\Powershell_av_colors.ico" placement="appLogoOverride" />
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.Default" />
</toast>
"@
$AppId = 'Microsoft.AutoGenerated.{A49227EA-5AF0-D494-A3F1-0918A278ED71}'
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::new()
$ToastXml.LoadXml($XmlString)
$Toast = [Windows.UI.Notifications.ToastNotification]::new($ToastXml)
$Toast | Get-Member -MemberType Event
Register-ObjectEvent -InputObject $Toast -EventName Activated -Action {
Out-File -FilePath C:\Temp\Event.txt -InputObject (Get-Date -Format 'o') -Append -Force
}
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($Toast)
@tauseedzaman
Copy link

what would be the code to show the trigger some code on dismissed of notification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment