在Windows 10中从命令行创建通知

daka

我有一个与键盘快捷键相关联的脚本,当我触发快捷键时,我希望显示一条确认脚本已执行的通知。

如何从脚本内部创建通知?

编辑

在Linux上,我曾经做过 command && notify-send "My message"

伊斯洛尔技术

在PowerShell中,您可以运行(从此处开始):

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

或这个(从这里开始):

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从命令行创建Windows 10恢复磁盘?

在Windows 10中从命令行打开xz文件

如何从命令行向Windows 10计算机发送通知

如何从命令行创建Windows EventLog源?

Windows 10从命令行打印为PDF

在Windows中从命令行创建符号链接,不带“ .lnk”

如何在Windows中从命令行创建空文件

正确运行devcon.exe(在Windows 10中从命令行启用/禁用设备)

如何从命令行在Windows 10中重置或清除用户配置文件?

在Windows中从命令行拍摄屏幕截图

如何在Windows中从命令行停止服务?

在 Windows 中从命令行打开 Visual Studio Code

Windows中的Python:从命令行进行编程

Windows 10如何创建命令行程序

为什么Windows版Git会创建无法从命令行删除的存储库?

Github Windows:从命令行创建的新分支未显示在github.com上

如何从命令行将Windows 10时钟同步到Internet?

在Windows 10上从命令行运行Java程序

在Windows 10命令行中启用git

在Windows 7中,如何从命令行更改代理设置?

如何从命令行知道在 Windows 中打开了哪个文件?

从命令行(在 Windows 中)对 FLA 文件执行 jsfl 脚本

如何在Windows 7中从命令行执行ShortCut

如何在Windows上从命令行在PhpStorm中打开项目

TensorFlow-如何在Windows中从命令行停止TensorBoard?

如何在Windows 8中从命令行运行Metro-Application?

如何在Windows中从命令行打印默认的Java类路径

如何在Windows 8中从命令行打开用于桌面的Internet Explorer?

在新窗口中从命令行在Windows中打开Chrome