#include "Tlhelp32.h"
#include "winbase.h"
// Function to kill Process using Process ID
int Killprocess(int nProcessID)
{
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, 0, nProcessID );
if (hProcess == NULL)
return -1;
BOOL nReturnVal = TerminateProcess( hProcess, 9 );
CloseHandle (hProcess);
return nReturnVal;
}
// Function to get all Process Name and Process ID
CString GetProcessNameandID()
{
HANDLE hSnapShot;
hSnapShot=CreateToolhelp32Snapshot (TH32CS_SNAPALL,NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize =sizeof(pEntry);
CString csProcessList;
DWORD dwID;
CString csProcessID;
//Get first process
Process32First (hSnapShot,&pEntry);
//Get all processes
while(1)
{
BOOL hRes=Process32Next (hSnapShot,&pEntry);
if(hRes==FALSE)
break;
csProcessList=csProcessList+pEntry.szExeFile;
dwID=pEntry.th32ProcessID;
csProcessID.Format("%i",dwID);
csProcessList=csProcessList +" "+csProcessID +"\r\n" ;
}
return csProcessList;
}
2 comments:
Thanks for posting. It works really well.
Post a Comment