C++定时关机程序

#include <bits/stdc++.h>
#include <winsock2.h>
#include <windows.h>
#include <windowsx.h>
#include <cstring>
#include <time.h>
#include <string>
#include <chrono>
#include <cinttypes>
#include <ctime>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
     ios::sync_with_stdio(0);
     int month, day, hour, minute, second;
    string year; 
     cout<<"                       欢迎使用定时关机程序!                             "<<endl; 
     cout<<endl;
    cout<<"                            作者:陶**                                  "<<endl;
    cout<<endl; 
     cout<<"                                                             Powerd By LTC"<<endl;
     cout<<endl;
     cout<<"                              Welcome!                                    "<<endl;
     cout<<endl;
     cout<<endl;
     cout<<"请输入5个整数,分别是年、月、日、小时、分钟(如果要让程序正常关机,请不要关闭改exe文件)"<<endl;
     cout<<"如果想要取消该进程,请在规定时间前运行一个程序,如果想显示此程序源码,输入code(不要大写)"<<endl;
     cout<<"如果想要立刻关机,输入now(不要大写)"<<endl; 
     cout<<"如果不需要,按第一行输入即可"<<endl;
     cout<<"请输入二十四时计时法的时间!!!"<<endl;
    time_t now = time(0);
    tm *ltm = localtime(&now);    
    cout<<"现在时间: "<<1900+ltm->tm_year<<"-"<<1+ltm->tm_mon<<"-"<<ltm->tm_mday<<" ";
    cout<<ltm->tm_hour<<":"<<ltm->tm_min<<":"<<ltm->tm_sec<<endl;
     while(cin>>year)
     {
         if(year=="code")
         {
             string ss="         system(shutdown -a);";
            ss.insert(ss.begin()+16, '"');
            ss.insert(ss.begin()+28, '"');
             cout<<"#include <bits/stdc++.h>"<<endl;
             cout<<"#include <windows.h>"<<endl;
             cout<<"using namespace std;"<<endl;
             cout<<"int main()"<<endl;
             cout<<"{"<<endl;
             cout<<"     ios::sync_with_stdio(0);"<<endl;
             cout<<"     while(true)"<<endl;
             cout<<"     {"<<endl;
             cout<<ss<<endl;
             cout<<"    }"<<endl;
             cout<<"    return 0;"<<endl;
             cout<<"}"<<endl;
             continue;
        }
        else if(year=="now")
        {
            system("shutdown -p");
            return 0;
        }
        else
        {
            int yy;
            stringstream ss;
            ss<<year;
            ss>>yy;
            cin>>month>>day>>hour>>minute>>second;
            time_t now = time(0);
            tm *ltm = localtime(&now);    
            cout<<"现在时间: "<<1900+ltm->tm_year<<"-"<<1+ltm->tm_mon<<"-"<<ltm->tm_mday<<" ";
            cout<<ltm->tm_hour<<":"<<ltm->tm_min<<":"<<ltm->tm_sec<<endl;
            cout<<"关机种子已经埋下!";
            while(true)
            {            
                time_t now = time(0);
                tm *ltm = localtime(&now);        
                if(1900+ltm->tm_year==yy && month==1+ltm->tm_mon && ltm->tm_mday==day && ltm->tm_hour==hour
                && ltm->tm_min==minute && ltm->tm_sec==second)
                {
                    system("shutdown -p");
                    return 0;
                }
                Sleep(1000);
            }
            return 0;
        }
    }
    return 0;
}

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值