说明:
相当于一个定时器,过固定的10天时间将程序重启
// kill.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include <shellapi.h> #include <time.h> // 定义10天的时间秒数 #define TEN_DAY (10*24*60*60) // 定义要定期调用执行的程序,这里是bat文件 const char* DestTop = "C:\\Documents and Settings\\Administrator\\桌面\\start.bat"; //const char * DestTop = "C:\\Users\\zhu\\Desktop\\star.bat"; int _tmain(int argc, _TCHAR* argv[]) { while(1) { SYSTEMTIME m_time; GetLocalTime(&m_time); int h=m_time.wHour; int m=m_time.wMinute; int s=m_time.wSecond; printf("%.2d:%.2d:%.2d\n",h,m,s); // 调用ShellExecuteA函数启动目标程序,SW_HIDE参数表示静默启动,不显示命令框 HINSTANCE hNewExe = ShellExecuteA(NULL, "open", DestTop, NULL, NULL, SW_HIDE); // 返回值小于等于32表示打开失败 if ((int)hNewExe <= 32) { printf("打开失败!\n"); break; } printf("Open start.bat Success!\n"); printf("From now Sleep 10 days...\n"); //开始等待10天 Sleep(TEN_DAY*1000 - (h*60*60+m*60+s)*1000 ); //10天后关掉相关进程 system("taskkill /im position_machine.exe"); printf("Kill position_machine.exe OK!\n"); Sleep(1000); system("taskkill /im SSF_AIR.exe"); printf("Kill SSF_AIR.exe OK!\n"); Sleep(1000); system("taskkill /im java.exe"); printf("Kill java.exe OK!\n"); Sleep(1000); system("taskkill /im cmd.exe"); printf("Kill cmd.exe OK!\n"); Sleep(10000); } return 0; }
时间: 2024-11-24 19:15:19