zoukankan      html  css  js  c++  java
  • 实用的关机

    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格式的文件便可以直接双击运行

  • 相关阅读:
    京东Java面试题(二)
    京东Java面试题(一)
    阿里java面试题
    Java垃圾回收机制
    MyBatis面试题
    Java IO流总结
    Spring中文文档
    Vue.js实战之组件之间的数据传递
    Vue.js实战之Vuex的入门教程
    Vue系列——在vue项目中使用jQuery及其第三方插件
  • 原文地址:https://www.cnblogs.com/ywj2013/p/3298023.html
Copyright © 2011-2022 走看看