Click here to Skip to main content
15,919,479 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralOperator Overloading Pin
Murad Duraidi16-Aug-05 1:48
Murad Duraidi16-Aug-05 1:48 
QuestionHow to get Handle of the specified process and kill the process??? Pin
Supriya Tonape16-Aug-05 1:20
Supriya Tonape16-Aug-05 1:20 
AnswerRe: How to get Handle of the specified process and kill the process??? Pin
ThatsAlok16-Aug-05 2:35
ThatsAlok16-Aug-05 2:35 
GeneralRe: How to get Handle of the specified process and kill the process??? Pin
Supriya Tonape17-Aug-05 2:54
Supriya Tonape17-Aug-05 2:54 
GeneralRe: How to get Handle of the specified process and kill the process??? Pin
ThatsAlok17-Aug-05 18:04
ThatsAlok17-Aug-05 18:04 
AnswerRe: How to get Handle of the specified process and kill the process??? Pin
David Crow16-Aug-05 4:06
David Crow16-Aug-05 4:06 
GeneralRe: How to get Handle of the specified process and kill the process??? Pin
Supriya Tonape17-Aug-05 3:03
Supriya Tonape17-Aug-05 3:03 
AnswerRe: How to get Handle of the specified process and kill the process??? Pin
Geert van Horrik16-Aug-05 4:18
Geert van Horrik16-Aug-05 4:18 
if you know the executable location, you can use this function:

<br />
bool CMyclass::CloseApplication(CString sFilename)<br />
{<br />
	// Declare variables<br />
	HANDLE hProcessSnap = NULL;<br />
	PROCESSENTRY32 pe32 = {NULL};<br />
	CString sCompare, sTemp;<br />
	CString sProcesm_sFilename = //Extract the filename from the sFilename, so you only have to pass notepad.exe<br />
#if (_MFC_VER < 0x0700)<br />
	sProcesm_sFilename.MakeLower();<br />
#else<br />
	CString sLowerTemp;<br />
	sLowerTemp = sProcesm_sFilename;<br />
	sProcesm_sFilename = sLowerTemp.MakeLower();<br />
#endif<br />
	<br />
	hProcessSnap = CreateToolhelp32Snapshot <br />
		(TH32CS_SNAPPROCESS, 0);<br />
	<br />
	pe32.dwSize = sizeof(PROCESSENTRY32);<br />
	if (Process32First(hProcessSnap, &pe32))<br />
	{<br />
		do<br />
		{<br />
			sCompare.Format("%s", pe32.szExeFile);<br />
<br />
#if (_MFC_VER < 0x0700)<br />
			sCompare.MakeLower();<br />
#else<br />
			CString sLowerTemp;<br />
			sLowerTemp = sCompare;<br />
			sCompare = sLowerTemp.MakeLower();<br />
#endif<br />
<br />
			if (sCompare == sProcesm_sFilename)<br />
			{<br />
				// Get handle to process<br />
				HANDLE hProcess = OpenProcess<br />
					(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);<br />
				<br />
				DWORD exCode;<br />
				GetExitCodeProcess(hProcess, &exCode);<br />
				TerminateProcess(hProcess, exCode);<br />
			}<br />
		} while (Process32Next(hProcessSnap, &pe32));<br />
	}<br />
	else<br />
	{<br />
		return false;<br />
	}<br />
	<br />
	return true;<br />
}<br />


Geert

Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
GeneralRe: How to get Handle of the specified process and kill the process??? Pin
Supriya Tonape17-Aug-05 3:01
Supriya Tonape17-Aug-05 3:01 
GeneralVideo RAM Usage Indicator Pin
Joel Holdsworth16-Aug-05 0:09
Joel Holdsworth16-Aug-05 0:09 
GeneralRe: Video RAM Usage Indicator Pin
Blake Miller16-Aug-05 5:18
Blake Miller16-Aug-05 5:18 
Generalmp3 streaming Pin
sebinfrancis15-Aug-05 23:45
sebinfrancis15-Aug-05 23:45 
GeneralProblem with serialization Pin
heavenode15-Aug-05 23:40
heavenode15-Aug-05 23:40 
GeneralRe: Problem with serialization Pin
Trollslayer16-Aug-05 1:26
mentorTrollslayer16-Aug-05 1:26 
GeneralRe: Problem with serialization Pin
heavenode16-Aug-05 1:44
heavenode16-Aug-05 1:44 
GeneralRe: Problem with serialization Pin
Ravi Bhavnani16-Aug-05 4:34
professionalRavi Bhavnani16-Aug-05 4:34 
QuestionTerminate an exe from another exe ? Pin
Amarelia15-Aug-05 23:40
Amarelia15-Aug-05 23:40 
AnswerRe: Terminate an exe from another exe ? Pin
mark novak16-Aug-05 0:32
mark novak16-Aug-05 0:32 
GeneralRe: Terminate an exe from another exe ? Pin
Trollslayer16-Aug-05 1:27
mentorTrollslayer16-Aug-05 1:27 
GeneralRe: Terminate an exe from another exe ? Pin
David Crow16-Aug-05 4:17
David Crow16-Aug-05 4:17 
GeneralRe: Terminate an exe from another exe ? Pin
Trollslayer16-Aug-05 7:56
mentorTrollslayer16-Aug-05 7:56 
GeneralRe: Terminate an exe from another exe ? Pin
Amarelia16-Aug-05 18:12
Amarelia16-Aug-05 18:12 
GeneralRe: Terminate an exe from another exe ? Pin
Amarelia16-Aug-05 18:13
Amarelia16-Aug-05 18:13 
AnswerRe: Terminate an exe from another exe ? Pin
David Crow16-Aug-05 4:09
David Crow16-Aug-05 4:09 
GeneralRe: Terminate an exe from another exe ? Pin
Amarelia16-Aug-05 18:11
Amarelia16-Aug-05 18:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.