PowerShell 显示气球提示框 2
https://www.itninja.com/blog/view/reboot-required-toast-notifications-for-windows-machines

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | out-null
$TimeStart = Get-Date
$TimeEnd = $timeStart.addminutes(360)
Do360
{
$TimeNow = Get-Date
if ($TimeNow -ge $TimeEnd)
{
Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue
Remove-Event click_event -ErrorAction SilentlyContinue
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
Exit
}
else
{
$Balloon = new-object System.Windows.Forms.NotifyIcon
$Balloon.Icon = [System.Drawing.SystemIcons]::Information
$Balloon.BalloonTipText = "A reboot is required in order to complete ESSO AccessAgent updating. Please reboot at your earliest convenience."
$Balloon.BalloonTipTitle = "Reboot Required"
$Balloon.BalloonTipIcon = "Warning"
$Balloon.Visible = $true;
$Balloon.ShowBalloonTip(20000);
$Balloon_MouseOver = [System.Windows.Forms.MouseEventHandler]{ $Balloon.ShowBalloonTip(20000) }
$Balloon.add_MouseClick($Balloon_MouseOver)
Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue
Register-ObjectEvent $Balloon BalloonTipClicked -sourceIdentifier click_event -Action {
Add-Type -AssemblyName Microsoft.VisualBasic
If ([Microsoft.VisualBasic.Interaction]::MsgBox('Would you like to reboot your machine now?', 'YesNo,MsgBoxSetForeground,Question', 'System Maintenance') -eq "NO")
{ }
else
{
shutdown -r -f
}
} | Out-Null
Wait-Event -timeout 7200 -sourceIdentifier click_event > $null
Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue
$Balloon.Dispose()
}
}
Until ($TimeNow -ge $TimeEnd)
it prompts every 2 hours for 6 hours. The highlighted 360 is for the over all length and 7200 is the time (in seconds) between prompts.
执行该脚本的显示效果:单击提示信息时,会显示另外一个提示框,点Yes时,会重启电脑;选择No时,每隔两小时会再次提醒。该提示信息只显示5秒,因为Windows系统设置默认只显示5秒。


但是关闭PowerShell ISE时,该提示图标就自动退出了。
解决方法:将上面的脚本保存为NotifyReboo.ps1, 然后新建bat脚本test.bat,内容如下:
@ECHO OFF
if "%1"=="hide" goto CmdBegin
start mshta vbscript:createobject("wscript.shell").run("""%~0"" hide",0)(window.close)&&exit
:CmdBegin SET CurrentPath=%~dp0 powershell.exe -sta -executionpolicy bypass -file "%CurrentPath%RebootNotify.ps1" Exit
也就是用test.bat脚本去调用NotifyReboot.ps1,然后在后台运行。
SET CurrentPath=%~dp0 这里是设置当前路径。需要把两个脚本放在同一个目录 下。然后,运行test.bat即可以看到上面的提示效果。
PowerShell 显示气球提示框 2的更多相关文章
- PowerShell 显示气球提示框 1
#加载 Winform 程序集,使用Out-Null抑制输出 [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.For ...
- 微信小程序API交互反馈,wx.showToast显示消息提示框
导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...
- Android学习笔记通过Toast显示消息提示框
显示消息提示框的步骤 这个很简单我就直接上代码了: Button show = (Button)findViewById(R.id.show); show.setOnClickListener(new ...
- 单一按钮显示/隐藏&&提示框效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使提示框居中显示&自定义提示框
ToastActivity.java文件: 1 public class ToastActivity extends AppCompatActivity { 2 private Button mbtn ...
- ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)
介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...
- echarts —— tooltip 鼠标悬浮显示提示框属性
最近一直在使用echarts,当然也被其中的各种属性整的头大,记录一下其中遇到的问题. tooltip:鼠标悬浮时显示的提示框. 今天想要记录的是[自定义提示框的内容],如下图,鼠标悬浮时提示框内显示 ...
- 微信小程序-提示框
提示框: wx.showToast(OBJECT) 显示消息提示框 OBJECT参数说明: 示例代码: wx.showToast({ title: '成功', icon: 'success', dur ...
- EasyUI-Tooltip(提示框)学习
引子: if($("#BLUETOOTH_a")){ $("#BLUETOOTH_a").tooltip({ position: 'right', conten ...
随机推荐
- day66 模板小结 [母板继承,块,组件]
小结: day65 1. 老师编辑功能写完 1. magic2函数 --> 用两层for循环解决 全栈8期之殇 问题 2. 模板语言 in 语法 {% if xx in xx_list %} { ...
- day 61 Django part-1 django的安装,以及初学者三件套(以及settings中的mysql配置)
我们的django到底是什么东西呢? 我们的代码都是在后台写的,包括我们的pycharm都是属于后台的工具,但是我们的后端开发说到底是需要开发完了之后拿到用户面前的,让我们的用户看到我们的东西,首先要 ...
- C#中的 Stream
目录: 什么是Stream? 什么是字节序列? Stream的构造函数 Stream的重要属性及方法 Stream的示例 Stream异步读写 Stream 和其子类的类图 本章总结 什么是Strea ...
- Apache系列:Centos7.2下安装与配置apache
Centos7.2下安装与配置apache(一) 配置机:腾讯云服务器,centos7.2 一.安装Apache服务(Apache软件安装包叫httpd) yum install httpd -y 二 ...
- XamarinAndroid组件教程RecylerView自定义适配器动画
XamarinAndroid组件教程RecylerView自定义适配器动画 如果RecyclerViewAnimators.Adapters命名空间中没有所需要的适配器动画,开发者可以自定义动画.此时 ...
- json信息的后台到前台的传输
公共方法: /** * 实际返回的是 response.setContentType("text/html;charset=utf-8"); * * @param o */ pub ...
- 机器学习系列-tensorflow-01-急切执行API
tensorflow急切执行概述 Eager execution is an imperative, define-by-run interface where operations are exec ...
- 反射与内置方法str del
1.反射 用字符串来操作类或者对象的属性 class People:# country= 'china'# def __init__(self,name):# self.name= name## de ...
- Navicat Premium for Mac的破解教程
Navicat Premium for Mac破解教程 https://www.jianshu.com/p/f3ef78deadaa 时间戳: https://tool.lu/timest ...
- MyBatis初探
首先下载MyBatis jar包, 可以去MyBatis中文官网下载 项目中导入MyBatis jar包和JDBC jar包(此处用的MySQL) 新建conf.xml 内容如下: <?xml ...