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的更多相关文章

  1. PowerShell 显示气球提示框 1

    #加载 Winform 程序集,使用Out-Null抑制输出 [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.For ...

  2. 微信小程序API交互反馈,wx.showToast显示消息提示框

    导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...

  3. Android学习笔记通过Toast显示消息提示框

    显示消息提示框的步骤 这个很简单我就直接上代码了: Button show = (Button)findViewById(R.id.show); show.setOnClickListener(new ...

  4. 单一按钮显示/隐藏&&提示框效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 使提示框居中显示&自定义提示框

    ToastActivity.java文件: 1 public class ToastActivity extends AppCompatActivity { 2 private Button mbtn ...

  6. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  7. echarts —— tooltip 鼠标悬浮显示提示框属性

    最近一直在使用echarts,当然也被其中的各种属性整的头大,记录一下其中遇到的问题. tooltip:鼠标悬浮时显示的提示框. 今天想要记录的是[自定义提示框的内容],如下图,鼠标悬浮时提示框内显示 ...

  8. 微信小程序-提示框

    提示框: wx.showToast(OBJECT) 显示消息提示框 OBJECT参数说明: 示例代码: wx.showToast({ title: '成功', icon: 'success', dur ...

  9. EasyUI-Tooltip(提示框)学习

    引子: if($("#BLUETOOTH_a")){ $("#BLUETOOTH_a").tooltip({ position: 'right', conten ...

随机推荐

  1. linux 学习笔记 防火墙设置

    1> 重新设置启动防火墙命令 #service iptables restart 2>添加防火墙规则命令 2.1 #service iptables stop 停止防火墙 2.2 #vi ...

  2. 在Eclipse中使用Junit进行单元测试

    单元测试与Junit4 单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证.单元测试是在软件开发过程中要进行的最低级别的测试活动,软件的独立单元将在与程序的其他部分相隔离 ...

  3. Git 使用问题记录

    问题一:新文件 add 后,提示有 modified 内容 描述:在 master 分支中增加了一个新的文件夹(-/cb4.6-zh),但执行 git add 后再查看状态却提示有 modified ...

  4. Adams/Car与Simulink联合仿真方法

    必须是Assembly装配体才行,并支持仿真设置.这里使用MDI_Demo_Vehicle模型,输出前缀为test1,输出选择files_only.然后OK输出. 生成的文件如下: 在Plant Ex ...

  5. RESTful restful api Representational State Transfer

    通俗直白讲:REST是一种编写风格,一种API接口规范.它的风格就是将对象(如学生)的状态(如增删改查,API接口版本号等等)通过其他方式传递,API的接口地址突显出描述的对象. -- == REST ...

  6. 【PYTHON】 Missing parentheses in call to 'print'

    Microsoft Windows [版本 10.0.15063] (c) 2017 Microsoft Corporation.保留所有权利. C:\Users\Jam>python Pyth ...

  7. php 将两个数组进行相加 http://blog.csdn.net/lcstrive/article/details/38331487

    刚刚在网上看到一个提问. 数组Array ( [0] => 1 [1] => 2 )和数组Array ( [0] => 5 [1] => 6 ) 怎么让他们想加得出: 数组Ar ...

  8. (转自知乎)Unicode编码

    很多人都把Unicode编码挂在嘴边,其实咱们现实生活中遇到的编码基本都是Unicode的 因为Unicode兼容了大多数老版本的编码规范例如 ASCII Unicode编码定义了这个世界上几乎所有字 ...

  9. 用canvas整个打飞机游戏

    声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 之前在当耐特的DEMO里看到个打飞机的游戏,然后就把他的图片和音频扒了了下来....自己凭着玩的心情重新写了一个.仅供娱乐哈......我 ...

  10. MyBatis 命名空间与命名解析

    命名空间 使用完全限定名来进一步区分语句. 命名解析 为了减少输入量,MyBatis 对所有的命名配置元素(包括语句,结果映射,缓存等)使用如下的命名解析规则: 完全限定名(比如“com.mypack ...