//////////////////////////////////////////////////////////////////////////
#include "tlhelp32.h" ==> h 필요.
void _LibProcSafeKill(); ==> function으로 작성.
//////////////////////////////////////////////////////////////////////////

 

void _LibProcSafeKill()
{
HANDLE hProcessSnap;
HANDLE hProcess;
DWORD dwPriorityClass;
CString strModuleName;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE) return;

// Set the size of the structure before using it.
pe32.dwSize = sizeof(PROCESSENTRY32);

// Retrieve information about the first process,
// and exit if unsuccessful
if(!Process32First(hProcessSnap, &pe32))
{
CloseHandle(hProcessSnap); // Must clean up the snapshot object!
return;
}

// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
// Retrieve the priority class.
dwPriorityClass = 0;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
if(hProcess == NULL)
continue;

strModuleName = (LPCTSTR)pe32.szExeFile;
strModuleName.MakeLower();
if(strModuleName.Find(_T("tos.exe")) > -1)
{
DWORD dwExitCode;
::GetExitCodeProcess(hProcess, &dwExitCode);
::TerminateProcess (hProcess, dwExitCode);
CloseHandle(hProcess);
break;
}
CloseHandle(hProcess);
} while(Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
}

 

+ Recent posts