标签:
一、Natalia.bat
双击这个文件可以运行Natalia
控制台在打开后会变成最小化,标题为PowerAssistant,黑色背景淡绿色文字
运行脚本Natalia.vbs
1 @ECHO OFF 2 3 REM 脚本最小化运行. 4 IF "%1" == "m" GOTO BEGIN 5 MSHTA VBScript:CreateObject("WSCript.Shell").Run("%~fs0 m",6)(Window.Close)&&EXIT 6 :BEGIN 7 8 REM 注释最后一定要跟一个解释器可识别半角字符,否则脚本会运行错误. 9 REM 设置命令行标题. 10 TITLE PowerAssistant 11 12 REM 设置命令行颜色. 13 REM 前景色(0=黑,1=蓝,2=绿,3=浅绿,4=红,5=紫,6=黄,7=白,8=灰,9=淡蓝). 14 REM 背景色(A=淡绿,B=淡浅绿,C=淡红,D=淡紫,E=淡黄,F=亮白). 15 COLOR 0A 16 17 REM 调用倒计时脚本. 18 CSCRIPT Natalia.vbs //NOLOGO 19 20 PAUSE
二、Natalia.vbs
在最上面的“定义常量部分”,可以设置预计关机的时间
1 Option Explicit 2 3 ‘定义常量 4 Const ObjHour = 23 ‘时 0-23 5 Const ObjMinute = 30 ‘分 0-59 6 Const ObjSecond = 00 ‘秒 0-59 7 8 ‘检查输入是否合法 9 Dim IsInputLegal 10 IsInputLegal = True 11 If ObjHour < 0 Or ObjHour > 23 Then 12 IsInputLegal = False 13 End If 14 If ObjMinute < 0 Or ObjMinute > 59 Then 15 IsInputLegal = False 16 End If 17 If ObjSecond < 0 Or ObjSecond > 59 Then 18 IsInputLegal = False 19 End If 20 If IsInputLegal = False Then 21 WScript.Echo "输入非法 时区间:[0-23] 分区间:[0,59] 秒区间:[0,59]" 22 WScript.Quit 23 End If 24 25 ‘定义变量 26 Dim ObjTime ‘目标时间 27 Dim CurTime ‘当前时间 28 Dim CurHour ‘当前时 29 Dim CurMinute ‘当前分 30 Dim CurSecond ‘当前秒 31 32 ObjTime = "目标时间:" & ObjHour & "时 " & ObjMinute & "分 " & ObjSecond & "秒" 33 34 Dim IsTimeOut 35 IsTimeOut = False 36 37 ‘时间到则终止循环 38 Do Until IsTimeOut = True 39 40 CurHour = Hour(Now) 41 CurMinute = Minute(Now) 42 CurSecond = Second(Now) 43 44 CurTime = "当前时间:" & CurHour & "时 " & CurMinute & "分 " & CurSecond & "秒" 45 WScript.Echo ObjTime & " | " & CurTime 46 47 If (CurHour = objHour And CurMinute = objMinute And CurSecond = objSecond) Or _ 48 (Hour(Now) = objHour And Minute(Now) = objMinute And Second(Now) = objSecond+1) Then 49 IsTimeOut = True 50 End If 51 52 WScript.Sleep(1000) 53 54 Loop 55 56 WScript.CreateObject("wscript.shell").Run "shutdown -s -t 300", 0 57 WScript.Echo vbCrlf 58 WScript.Echo "收拾收拾准备睡觉啦!5分钟后我会把你的电脑关掉哦~~~" 59 WScript.Echo "在控制台输入命令 shutdown -a 可以取消关机计划" 60 WScript.Echo vbCrlf
三、运行效果
标签:
原文地址:http://www.cnblogs.com/masonlu/p/4691672.html