Answer the question
In order to leave comments, you need to log in
How to write a process to freeze and unfreeze?
I wrote this code:
#include <Windows.h>
#include <TlHelp32.h>
#include <iostream>
using namespace std;
bool KillProcByPid(DWORD pid) { // Метод убийства процесса
DWORD ExitCode;
HANDLE hp;
bool ret = true;
if (pid)
{
hp = OpenProcess(PROCESS_ALL_ACCESS, true, pid);
if (hp)
{
GetExitCodeProcess(hp, &ExitCode);
ret = TerminateProcess(hp, ExitCode);
}
else
{
return false;
}
}
else
{
return false;
}
CloseHandle(hp);
return ret;
}
int GetProcesByName(wstring name) { // Метод получения PID
HANDLE snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pInfo = { 0 }; pInfo.dwSize = sizeof(PROCESSENTRY32);
while (Process32Next(snapShot, &pInfo))
{
if (pInfo.szExeFile == name)
{
CloseHandle(snapShot);
return pInfo.th32ProcessID;
}
}
CloseHandle(snapShot);
return 0;
}
int main() {
int pID = GetProcesByName(L"Name.exe"); //Название вашего процесса, по которому ищется PID
cout << pID << "\n"; // Вписываем в консоль его PID
KillProcByPid(pID); // Убиваем процесс по PID
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question