#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
#include <userenv.h>
#include <winnt.h>
#include <WtsApi32.h>
#include <process.h>
DWORD aProcesses[1024], cbNeeded, cProcesses;
HANDLE hProcess;
bool bProcRunning = false;WCHAR filename[260];
wcscpy(filename, L"Application.exe");
bool bLoggedUser;
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (wcscmp(pEntry.szExeFile, filename)==0)
{
bProcRunning=true;
if( bLoggedUser == false)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
Aucun commentaire:
Publier un commentaire