Create notification from command line in Windows 10
9,082
In PowerShell you can run (from here):
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"Script Completed!","Your script ran succesfully!",[system.windows.forms.tooltipicon]::None)
Or this (from here):
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: Your script has been completed successfully"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "Test1"
$toast.Group = "Test2"
$toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(5)
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Script Completed!")
$notifier.Show($toast);
Related videos on Youtube
Author by
daka
Updated on September 18, 2022Comments
-
daka over 1 year
I have a script that is associated with a keyboard shortcut, when I trigger the shortcut, I want a notification to appear confirming that the script executed.
How do I create a notification from inside a script?
EDIT
On Linux, I used to do
command && notify-send "My message"
-
Aardwolf about 4 yearsecho msgbox "the message that you want" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs"
-
-
daka about 4 yearsIs there a way to auto clear it after a few seconds?
-
daka about 4 yearsAlso, I don't want an icon to show in the taskbar, notification only.
-
Yisroel Tech about 4 years@daka, added 2nd method that has does show in the taskbar and has an expireing-seconds parts
-
daka about 4 yearsRegarding the second way, removing
Notification:
from$notificationTitle
makes it stop working, why? -
Yisroel Tech about 4 years@daka works for me (see i.imgur.com/AzjMFwu.png). Did you make sure to leave the opening quotes before it?
-
daka about 4 yearsYep I did, very weird.
-
Wasif over 3 yearsTo clear it after a few seconds,
Start-Sleep
then.Dispose()
. -
Ben Racicot almost 3 years@YisroelTech any way to keep it from disappearing? I'm trying to work on some tasks WHILE a notif is open. Perhaps making it manual close only by the "X" button?
-
Yisroel Tech almost 3 years@BenRacicot I do not believe so