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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3229|回复: 47
收起左侧

[Python 原创] 21天自动重启电脑

  [复制链接]
20230713G001133 发表于 2024-2-1 17:56
import os
import time
from datetime import datetime, timedelta

# 定义重启周期为21天
restart_period = 21

# 获取当前日期距离指定日期的剩余秒数
def seconds_until_next_restart():
    current_time = datetime.now()
    next_restart_time = (current_time + timedelta(days=restart_period)).replace(hour=0, minute=0, second=0)
    seconds_until_restart = (next_restart_time - current_time).total_seconds()
    return seconds_until_restart

# 主程序
if __name__ == '__main__':
    while True:
        seconds_until_restart = seconds_until_next_restart()
        time_remaining = str(timedelta(seconds=seconds_until_restart))

        # 清除上一次的输出内容
        print('\r\033', end='')

        print(f"距离下次重启还有 {time_remaining}", end='')
        time.sleep(1)  # 每隔一秒检查一次是否需要重启
        if seconds_until_restart <= 0:
            os.system("shutdown /r /t 1")  # 执行重启命令


image.png

免费评分

参与人数 6吾爱币 +6 热心值 +5 收起 理由
chlianfu + 1 + 1 鼓励转贴优秀软件安全工具和文档!
人二 + 1 虽然可以,但是Windows有自动的任务计划
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
wuming4 + 1 用心讨论,共获提升!
matrixzpc + 1 我很赞同!
开心熊猫741 + 1 + 1 谢谢@Thanks!

查看全部评分

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

爱飞的猫 发表于 2024-2-2 01:46
… 善用系统定时任务

免费评分

参与人数 3吾爱币 +2 热心值 +3 收起 理由
cdroad + 1 + 1 哈哈哈哈哈哈哈哈哈
jstar + 1 我很赞同!
苏紫方璇 + 1 + 1 我很赞同!

查看全部评分

CQGaxm 发表于 2024-2-1 18:11
no1434 发表于 2024-2-2 00:34
hackerSQL 发表于 2024-2-1 18:00
定时重启呗
vethenc 发表于 2024-2-1 18:01
感谢分享萝卜刀
gxlibai 发表于 2024-2-1 18:34
窗口关闭了不就停止了
鹿鸣 发表于 2024-2-1 18:44
电脑21天不关?
 楼主| 20230713G001133 发表于 2024-2-1 18:58
鹿鸣 发表于 2024-2-1 18:44
电脑21天不关?

普通电脑基本上什么时候使用就什么时候打开,但是服务器。。。。。就不一定了
任国富 发表于 2024-2-1 19:23
感谢你的分享
jinmouyuzhao 发表于 2024-2-1 19:50
21天重启电脑时间间隔太长
oeo1oeo1 发表于 2024-2-1 19:54
很好,我的电脑长期不关,这样定期重启下挺好
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-4-29 17:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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