win7设置定时开关机

win7设置定时开关机

win7定时开关机

利用休眠来代替关机,然后定时唤醒,再重启
启用休眠

如果执行shutdown -h提示没有启用休眠功能,则先执行以下命令
powercfg -hibernate on

定时休眠
使用:shutdown -h -f -t 1800 //-t参数对休眠无效,会被任务是错误的命令
正确使用:at 14:00 shutdown -h -f//14:00强制休眠

定时开机
想使用创建计划任务来唤醒电脑,但是一直不成功,百度的各种方法都试过,后来使用工具WakeupOnStandBy成功唤醒,wosb.exe 下载地址:https://yunpan.cn/cPtEiiiRVYAaS 访问密码 b08f
wosb.exe /closeall //清空wosb.exe创建的定时任务
wosb.exe /run /systray /ami tm="15:00" file="shutdown.exe" params="-r -f -t 0" //15:00唤醒,并且唤醒后重启电脑
注意:如果系统没有启用“允许使用唤醒定时器”功能,唤醒将失败,解决方法可参考我的另一篇文章“电源管理”:http://blog.csdn.net/jin_huan11/article/details/51671556

代码示例
void Util::timerShutdown(EMessageType type, QTime exeTime, bool bImmediate)
{
    //时间无效
    if(!bImmediate && !exeTime.isValid())
    {
        g_log->logFunc2(LOG_INFO, "shutdown: %d, time %s is invalid.", type
                        , TIME_TO_STRING(exeTime).toUtf8().data());
        return;
    }

    //计算exexTime距当前的时间 msc
    int msc = 0;
    if(!bImmediate)
    {
        msc = mescToCurrTime(exeTime);
    }

    QString filePath;
    //关机命令
    if(type == EMSG_SHUTDOWN)
    {
#ifndef WAkEUPONSTANDBY
        filePath = "shutdown -s -t " + QString::number(msc / 1000);
#else
        //用睡眠来代替关机,这样可以使用wakeuponstandby唤醒电脑
        //use sleep replace shutdown
        //shutdown -h -t 1800, "-t" is invalid
        filePath = "powercfg -hibernate on";    //使用powercfg来启用电脑睡眠功能
        Util::startProgram(filePath, false, true);
        if(bImmediate)
        {
            filePath = "shutdown -h -f";
        }
        else
        {
            //由于shutdown -h 不能带时间参数, 所以使用at命令操作
            filePath = "at /delete /yes";       //清除上一次的at命令
            Util::startProgram(filePath, false, true);
            filePath = "at " + TIME_TO_STRING(exeTime) + " shutdown -h -f";
        }
#endif
    }
    //开机/唤醒命令
    else if(type == EMSG_STANDBY)
    {
#ifdef WAkEUPONSTANDBY
        filePath = "\"" + qApp->applicationDirPath() + "/wosb.exe\"";
        //close all timer
        QString commandStr = filePath + " /closeall";   //关闭之前的wosb命令
        Util::startProgram(commandStr, false, true);
        //stand up
        filePath += " /run /systray /ami tm=" + TIME_TO_STRING(exeTime) + " file=\"shutdown.exe\" params=\"-r -f -t 0\"";
#endif
    }
    //重启命令
    else if(type == EMSG_REBOOT)
    {
        filePath = "shutdown -r -f -t " + QString::number(msc / 1000);
    }

    bool bShutdown = Util::startProgram(filePath, false, false);

    g_log->logFunc2(LOG_INFO, "%s result: %d", filePath.toUtf8().data(), bShutdown);
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值