Erstellen Sie eine Benachrichtigung über die Befehlszeile in Windows 10

Erstellen Sie eine Benachrichtigung über die Befehlszeile in Windows 10

Ich habe ein Skript, das mit einer Tastenkombination verknüpft ist. Wenn ich die Tastenkombination auslöse, möchte ich, dass eine Benachrichtigung angezeigt wird, die die Ausführung des Skripts bestätigt.

Wie erstelle ich eine Benachrichtigung innerhalb eines Skripts?

BEARBEITEN

Unter Linux habe ichcommand && notify-send "My message"

Antwort1

In PowerShell können Sie Folgendes ausführen (vonHier):

[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)

Oder dies (vonHier):

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

verwandte Informationen