first commit
This commit is contained in:
commit
55eb9666e9
10 files changed
+929
No files matched your search
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <iostream>
|
||||
|
||||
void killProcessByName(const std::wstring& processName) {
|
||||
HANDLE hProcessSnap;
|
||||
HANDLE hProcess;
|
||||
PROCESSENTRY32 pe32;
|
||||
DWORD dwPriorityClass;
|
||||
|
||||
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (hProcessSnap == INVALID_HANDLE_VALUE) {
|
||||
std::wcerr << L"CreateToolhelp32Snapshot (of processes) failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
if (!Process32First(hProcessSnap, &pe32)) {
|
||||
std::wcerr << L"Process32First failed" << std::endl;
|
||||
CloseHandle(hProcessSnap);
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
if (processName == pe32.szExeFile) {
|
||||
hProcess = OpenProcess(PROCESS_TERMINATE, 0, pe32.th32ProcessID);
|
||||
if (hProcess != NULL) {
|
||||
TerminateProcess(hProcess, 0);
|
||||
CloseHandle(hProcess);
|
||||
std::wcout << L"Terminated process: " << pe32.szExeFile << std::endl;
|
||||
}
|
||||
}
|
||||
} while (Process32Next(hProcessSnap, &pe32));
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
}
|
||||
Reference in new issue
Block a user