#include <windows.h>
#include <tlhelp32.h>
#include <cstdio>
using namespace std;
void killprocessbyname(char *executable_name)
{
printf("killing %s ... ", executable_name);
PROCESSENTRY32 procentry32 = {sizeof(PROCESSENTRY32)};
HANDLE handle_process, handle_processes = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(Process32First(handle_processes, &procentry32))
{
do
{
if(CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, procentry32.szExeFile, -1, executable_name, -1) == CSTR_EQUAL)
{
if((handle_process = OpenProcess(PROCESS_TERMINATE, FALSE, procentry32.th32ProcessID)) != NULL)
{
TerminateProcess(handle_process, 0);
CloseHandle(handle_process);
printf("succeeded!");
}
}
}
while(Process32Next(handle_processes, &procentry32));
CloseHandle(handle_processes);
}
printf("\n");
}
int main()
{
wchar_t *exepath = new wchar_t[MAX_PATH];
int exepath_length = GetModuleFileNameW(NULL, exepath, MAX_PATH);
wchar_t *currentdir = new wchar_t[MAX_PATH];
GetCurrentDirectoryW(MAX_PATH, currentdir);
while (exepath[exepath_length] != '\\')
{
exepath_length--;
}
exepath[exepath_length + 1] = '\0';
SetCurrentDirectoryW(exepath);
delete[] exepath;
char *proc2kill = new char[MAX_PATH];
FILE *procfile = fopen("proc", "r");
if (procfile != NULL)
{
while (!feof(procfile))
{
fgets(proc2kill, MAX_PATH, procfile);
killprocessbyname(proc2kill);
}
delete[] procfile;
}
SetCurrentDirectoryW(currentdir);
delete[] currentdir;
}
And the code doesn't do anything. Can anyone tell me where I'm wrong?
Thanks in advance.


Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Back to top








