Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to terminate a executing programme.but i don't know how to do it ,iknow first i have to find the process of the program ,but which funtion i have to use .anybody have any source code to demonstrate the whole procedure?thx very much~
Posted

 
Share this answer
 
Comments
markfilan 29-Jun-11 3:21am    
thanks i solved the problem.
Prerak Patel 29-Jun-11 3:23am    
You are welcome.
BOOL KillProcess(CString strProcess)
{
	HANDLE hProcessSnap;
	BOOL bRet = TRUE;
	CString csProcessList = _T("");
	DWORD dwID = 0;
	PROCESSENTRY32 pe32;

	// Take a snapshot of all processes in the system
	hProcessSnap=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS,0);
	if(hProcessSnap == INVALID_HANDLE_VALUE)
	{
		bRet = FALSE;
		return bRet;
	}

	// 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 );
		bRet = FALSE;
		return bRet;
	}
	// Now walk the snapshot of processes, and
	// display information about each process in turn
	while( Process32Next( hProcessSnap, &pe32 ))
	{

		if(strProcess.Compare(pe32.szExeFile)==0)
		{
			dwID = pe32.th32ProcessID;
			bRet = TerminateProcessByID(dwID);
			return bRet;
		}

	}
	CloseHandle( hProcessSnap );
	return bRet;
}
 
Share this answer
 
Comments
markfilan 29-Jun-11 3:22am    
thank you very much ~
ShilpiP 29-Jun-11 4:24am    
Most Welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900