Game Dev/Article

Kill Process

AKer 2008. 7. 18. 12:39
반응형
BOOL KillProcess(char *szProcess)
{
	if(szProcess==NULL)
		return FALSE;

	HANDLE hProcessSnap = NULL; 
	BOOL bRet = FALSE; 
	PROCESSENTRY32 pe32 = {0}; 

	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);  

	if (hProcessSnap == INVALID_HANDLE_VALUE) 
		return FALSE; 

	pe32.dwSize = sizeof(PROCESSENTRY32); 

	if (Process32First(hProcessSnap, &pe32)) 
	{ 
		BOOL bGotModule = FALSE; 
		MODULEENTRY32 me32 = {0};  

		do 
		{ 
			if (::lstrcmpi(pe32.szExeFile, szProcess) == 0)
			{
				HANDLE hProcess = NULL;
				DWORD Code = 0;

				hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE, pe32.th32ProcessID); 
				GetExitCodeProcess(hProcess, &Code);

				if (TerminateProcess(hProcess, Code))
				{
					WaitForSingleObject(hProcess, 1000);
					bRet = TRUE;
				} 

				CloseHandle(hProcess);
				break;
			}
		} 

		while (Process32Next(hProcessSnap, &pe32)); 
	}    

	CloseHandle (hProcessSnap); 
	return bRet;
}
반응형

'Game Dev > Article' 카테고리의 다른 글

EnumWindow  (0) 2008.07.22
Memory Mapped File  (0) 2008.07.22
Capture Screen  (0) 2008.06.16
Send Stream to Notepad  (0) 2008.06.09