본문 바로가기
C & C++/C & C++

프로세스 찾아 죽이기

by izen8 2011. 10. 26.
반응형

#include <tlhelp32.h>


bool CH7TrayDlg::KillProcess( CString sExeName )

sExeName.MakeUpper(); 

HANDLE hSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 ); 

if ( (int)hSnapshot != -1 ) 

PROCESSENTRY32 pe32 ; 

pe32.dwSize=sizeof(PROCESSENTRY32); 

BOOL bContinue ; 

CString strProcessName; 

if ( Process32First ( hSnapshot, &pe32 ) ) 

do 

strProcessName = pe32.szExeFile; //strProcessName이 프로세스 이름; 

strProcessName.MakeUpper(); 

if( ( strProcessName.Find("H7.EXE",0) != -1 ) ) 

HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, 0, pe32.th32ProcessID ); 

if( hProcess ) 

DWORD       dwExitCode; 

GetExitCodeProcess( hProcess, &dwExitCode); 

TerminateProcess( hProcess, dwExitCode); 

CloseHandle(hProcess); 

CloseHandle( hSnapshot ); 

return TRUE; 

return FALSE; 

bContinue = Process32Next ( hSnapshot, &pe32 ); 

} while ( bContinue ); 

CloseHandle( hSnapshot ); 

return FALSE;

}

반응형

댓글