c++定時重啟某個windows程序


string getTime()
{
    time_t timep;
    time(&timep);
    char tmp[64] = {0};
    //獲取時間 時分秒
    strftime(tmp, sizeof(tmp), "%H:%M:%S", localtime(&timep));
    return tmp;
}
 
 
 
string ltime_end = getTime();
   if (ltime_end == "00:00:30")
   {
       for (int i = 0; i < 10; i++)
           {
               DWORD ldatasnappid = GetProcessIDByName("ES_Svr.exe") ;
               if (ldatasnappid != 0)
               {
                    string ss = "TaskKill /F /PID " + to_string(ldatasnappid);
                       WinExec(ss.c_str(),SW_SHOWMINIMIZED);
                    Sleep(3000);
               }
 
           }
 
           DWORD ldatasnappid2 = GetProcessIDByName("ES_SvrWork64.exe") ;
           if (ldatasnappid2 == 0) {
               string datasnap1 = "D:\\adg\\dataap\\Snapvr\\ES_Svr.exe";
               string datasnap2 = "D:\\adg\\datnap\\Snap\\ES_Svr.exe";
               string datasnap3 = "D:\\adg\\daap\\Sna\\ES_Svr.exe";
 
               TCHAR CurrentPath[MAX_PATH]={0};
                GetCurrentDirectory(MAX_PATH,CurrentPath);
                SetCurrentDirectory("D:\\adg\\hgf\\fgh\\");//改成你想調用的路徑
                WinExec(datasnap1.c_str(),SW_SHOWMINIMIZED);
                SetCurrentDirectory(CurrentPath);//設置回原來主程序的當前路徑
 
               Sleep(5000);
               GetCurrentDirectory(MAX_PATH,CurrentPath);
                SetCurrentDirectory("D:\\adg\\asd\\asd\\");//改成你想調用的路徑
                WinExec(datasnap2.c_str(),SW_SHOWMINIMIZED);
                SetCurrentDirectory(CurrentPath);//設置回原來主程序的當前路徑
               Sleep(5000);
                GetCurrentDirectory(MAX_PATH,CurrentPath);
                SetCurrentDirectory("D:\\adg\\dsa\\dsa\\");//改成你想調用的路徑
                WinExec(datasnap3.c_str(),SW_SHOWMINIMIZED);
                SetCurrentDirectory(CurrentPath);//設置回原來主程序的當前路徑
 
           }
 
 
 
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM