吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1053|回复: 3
收起左侧

[其他原创] autohotkey v2写的一个简单的windows倒计时关机脚本

[复制链接]
Dengyunzhe 发表于 2023-7-25 16:01

SingleInstance force ; 确保脚本只有一个实例在运行

input:= InputBox("设置定时关机, 请输入关机倒计时时间(分钟):", "时间设置")

if input.result="Cancel"{
    ExitApp
    return
}

else
    Minutes :=input.value

; 检查输入是否合法
If (!IsNumber(Minutes) || Minutes <= 0) {
    Result := MsgBox("你要立刻关机吗?",, "YesNo")
    if Result = "Yes"{
        ;MsgBox "You pressed Yes."
        Shutdown 1 ; 1 表示关机,更多选项可以参考 AHK 文档
        ExitApp ; 关闭GUI后停止脚本的执行
        return
    }

    else{
        ;MsgBox "You pressed No."
        ExitApp ; 关闭GUI后停止脚本的执行
        return
    }
}

; 弹出确认框
Result := MsgBox(Format("关机确认, 确定要在{1}分钟后关机吗?",Minutes),, "YesNo")
    if Result = "No"{
        ExitApp ; 关闭GUI后停止脚本的执行
        return
    }

; 开始倒计时
global time:=Minutes*60
global countdownGui := 0
global countdownText := ""
ShowCountdownGUI()
return

; 检查是否是数字
IsNumber(number) {
    return RegExMatch(number, "^\d+$")
}

ShowCountdownGUI() {
    global time

    Mygui:=Gui()

    MyGui.SetFont("s24","Font")
    minu:=Floor(time/60)
    sec:=time-minu*60
    if minu<10
        global CountdownText:=Mygui.Add("Text","x50 y30 w100 h30 ","0" . minu . ":0" . sec)
    else
        global CountdownText:=Mygui.Add("Text","x50 y30 w100 h30 ",minu . ":0" . sec)
    MyGui.SetFont("s14","Font")
    StopTimer:=Mygui.Add("Button","Default x50 y70 w100 h30","停止关机")
    StopTimer.OnEvent("Click", ButtonStop)  ; 当点击时, 调用 ButtonStop
    MyGui.Title :="关机"
    Mygui.show("w200 h150")
    myGui.OnEvent("Close", ButtonStop)

    setTimer CountDown, 1000
    return

    CountDown(){
        global CountdownText
        global time
        time := time - 1
        minu:=Floor(time/60)
        sec:=time-minu*60
        if minu<10
            if sec<10
                CountdownText.Text:="0" . minu . ":0" . sec
            else
                CountdownText.Text:="0" . minu . ":" . sec
        else 
            if sec<10
                CountdownText.Text:= minu . ":0" . sec
            else
                CountdownText.Text:= minu . ":" sec

        if (time <= 0) {
            shutdown 1

            SetTimer , 0
            ExitApp
            Return
        }
        Return

    }

    ButtonStop(*){
        ;SetTimer , 0
        ;MsgBox "关机已停止!"
        ExitApp
        Return

    }
}





免费评分

参与人数 1吾爱币 +5 热心值 +1 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

xiatongxue 发表于 2023-7-29 22:27
这...我记得不是有shell吗
 楼主| Dengyunzhe 发表于 2023-7-30 17:33
xiatongxue 发表于 2023-7-29 22:27
这...我记得不是有shell吗

终端命令的话好像是不会一直显示剩余时间的,我用的win11,别的版本不知道,

这个脚本只是加了个显示时间的窗口
jjyywg 发表于 2023-10-13 21:31
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 04:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表