#include <iostream>
#include <Windows.h>
#include <time.h>
#include <tlhelp32.h>
#include <tchar.h>
using namespace std;
int getnum(int minn, int maxn)
{
int ans = minn;
for (int i = minn; i < maxn; i++)
ans += rand() % 2;
return ans;
}
BOOL KillProcessByName(const TCHAR* lpszProcessName)
{
unsigned int pid = -1;
BOOL retval = TRUE;
if (lpszProcessName == NULL)
return -1;
DWORD dwRet = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(PROCESSENTRY32);
int flag = Process32First(hSnapshot, &processInfo);
// Find the process with name as same as lpszProcessName
while (flag != 0)
{
if (_tcscmp(processInfo.szExeFile, lpszProcessName) == 0)
{
// Terminate the process.
pid = processInfo.th32ProcessID;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
if (TerminateProcess(hProcess, 0) != TRUE)
{
// Failed to terminate it.
retval = FALSE;
break;
}
}
flag = Process32Next(hSnapshot, &processInfo);
} // while (flag != 0)
CloseHandle(hSnapshot);
if (pid == -1)
return FALSE;
return retval;
}
int main()
{
srand(time(0));
unsigned long long num = 0;
int i, a;
cout << "最小等待时间:";
cin >> i;
cout << "最大等待时间:";
cin >> a;
while (1)
{
KillProcessByName(_T("StudentMain.exe"));
Sleep(getnum(500, 1500));
system("start 启动极域的脚本(不能带空格)");
Sleep(500);
cout << "执行" << ++num << "次" << endl;
}
return 0;
}
懂得都懂,不断地链接断网,对极域的日志处理一下