//////////////////////////////////////////////////////////////////////////
#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);
}
'프로그래밍 > VC++ 개발 코딩' 카테고리의 다른 글
찾기다이아로그박스(Find Dialog box) dialogbox (0) | 2014.01.17 |
---|---|
VC2003 명령중 컴파일(Command line compile) (0) | 2014.01.17 |
현재시간구하기 (0) | 2014.01.17 |
RichEditCtrl, RichEdit 사용해보자 (0) | 2014.01.17 |
CreateThread 만들어보자 (0) | 2014.01.17 |