简单定时关机和睡眠程序代码

#include
#include
#include
#include
//强行指定入口,使无窗口.windows release 大小只有g++的十分之一左右
// #pragma comment (linker ,"/subsystem:\"Windows\" /entry:\"mainCRTStartup\"")

using namespace std;


VOID ThreadPro()
{
char cmd[50] = "shutdown -s -t ";
char SHP[50] = "shutdown -h";
char t[8];

//计算当前时间
time_t raw_time;
raw_time=time (NULL);
raw_time+=28800;
long m_mod=raw_time%86400;

long t1 = 82800 - m_mod;
long t2 = 45000 - m_mod;
// cout << t1 << t2 << endl;
//23:00定时关机
if (t1<=300&&t1>=0){
itoa(t1,t,10);
system(strcat(cmd,t));
exit(0); //确保执行一次,并正常退出该程序
}
//12:30定时睡眠
if (t2<=3&&t2>=0){
system(SHP);
}
Sleep(500);
}

int main(void)
{
while(TRUE)
{
ThreadPro();
Sleep(1200);
}

return 0;
}

相关文档
最新文档