I'm trying to make a small PowerShell program to display a toast notification after log on. I'd like the custom toast notification will stay there until user closes it. But but it disappears quickly. (about 5 seconds)
How can I do that ?
Script:
Import-Module BurntToast
$button = New-BTButton -Dismiss -Content "OK"
New-BurntToastNotification -Text 'Yoooo, this is a toast notification... from PowerShell!' -Button $button
The following works, using a variety of cmdlets from the BurntToast
module, as of v0.8.5:
Submit-BTNotification -Content (
New-BTContent -Scenario IncomingCall `
-Audio (New-BTAudio -Silent) `
-Visual (
New-BTVisual -BindingGeneric (
New-BTBinding -Children (New-BTText -Content 'Testing...') `
-AppLogoOverride (
New-BTImage -AppLogoOverride -Crop Circle -Source $env:windir\System32\wpcatltoast.png
)
)
)
)
-Scenario IncomingCall
is the key to making the notification "sticky".New-BTAudio -Silent
suppresses the sound that accompanies the notification when it first appears.
New-BTAudio -Source ms-winsoundevent:Notification.Default
is not effective, as -Scenario IncomingCall
seems to override it (the same goes for attempts to select any other sound).Note:
No button for dismissal is created, because a close icon is available by default.
While this Microsoft Q&A post suggests that adding a button implicitly makes a notification sticky, at least in the context of the BurntToast
module that is not true, as you've experienced.
The docs for the underlying .NET APIs suggest that the Reminder
and Alarm
scenario values too make a notification sticky, but at least in the context of the BurntToast
module that is not true; in fact, the latter seems to ignore these -Scenario
values as of v0.8.5 and uses a default notification (same as -Scenario Default
).
While there is a way to modify the default display duration (which is 5
seconds) via a registry value, as shown below, this requires a logoff or reboot to take effect, which means that you can not change it temporarily, in-session, and it will apply to all notifications (that do not explicitly control their display duration).
# Set the default display duration to 300 seconds == 5 minutes.
# Requires logoff or reboot to take effect.
Set-ItemPropert 'HKCU:\Control Panel\Accessibility' MessageDuration 300