On Error Resume Next
Dim sRunTime, aTime, iHour, iMinute, Wshshell, Now_time, closetime
CloseTime = 60
Now_time = time()
Set Wshshell = CreateObject("WScript.Shell")
sRunTime = InputBox("小杨之作,可以选择“关机时刻”或者“延迟关机时间”:" & vblf & vblf & "时间:" & Now_time & " (小时0-23,分秒00-59)"& vblf & "延时:正整数(单位分钟)" & vblf & vblf & "退出请单击“取消”。", "定时关机", Now_time)
If sRunTime = "" Then
Wshshell.Popup "定时关机没有启用,本程序即将关闭!", 2 , "定时关机"
WScript.Sleep 3000
Wscript.Quit
End If
If IsDate(sRunTime) = True Then
getstr1 = MsgBox("设置成功!系统将在 " & sRunTime & " 关机!放弃请单击“取消”!", 1 + 48, "定时关机")
If getstr1 = vbcancel Then
Wshshell.Popup "定时关机已经放弃,本程序即将关闭!", 5 , "定时关机",0 + 16
Wscript.Quit
End If
aTime = Split(sRunTime, ":")
iHour = CInt(aTime(0))
iMinute = CInt(aTime(1))
iSecond = CInt(aTime(2))
Do While True
Wscript.Sleep 500
If (Hour(Now) = iHour) And (Minute(Now) = iMinute) And (Second(Now) = iSecond) Then
For i = CloseTime To 1 Step - 5
yesorno = WshShell.Popup ("指定的关机时间 " & sRunTime & " 到了!" & i &" 秒后系统将关闭,取消定时关机请点击“否”!", 5 , "定时关机", 4 + 32 )
select case yesorno
case 7
Wscript.Quit
case 6
WshShell.run "shutdown /s /t 0",0,false
Wscript.Quit
end select
Wscript.Sleep 1000
Next
WshShell.run "shutdown /s /t 0",0,false
Wscript.Quit
end if
Loop
Else Do
getstr2 = MsgBox("设置成功!系统将在 " & sRunTime & " 分钟后关机!放弃请单击“取消”!", 1 + 48, "定时关机")
If getstr2 = vbcancel Then
Wshshell.Popup "定时关机已经放弃,本程序即将关闭!", 3 , "定时关机" ,0 + 16
Wscript.Quit
End If
WScript.Sleep(1000 * 60 * sRunTime)
For i = CloseTime To 1 Step - 5
yesorno = WshShell.Popup (sRunTime & "分钟倒计时时间到了!" & i &" 秒后系统将关闭,取消定时关机请点击“否”!", 5 , "定时关机", 4 + 32 )
select case yesorno
case 7
Wscript.Quit
case 6
WshShell.run "shutdown /s /t 0",0,false
Wscript.Quit
end select
Wscript.Sleep 1000
Next
WshShell.run "shutdown /s /t 0",0,false
Wscript.Quit
Loop
End If
最后将上面的代码保存为.vbs或者.vbe格式的文件便可以直接双击运行