bool bFind = false;
do
{
ULONG nProcessID = FindProcessID("testapp.exe");
if ( nProcessID > 0)
{
bFind = true;
HANDLE hProcessHandle;
hProcessHandle = ::OpenProcess( PROCESS_TERMINATE, FALSE,nProcessID );
TerminateProcess( hProcessHandle, 4 );
}
else
{
bFind = false;
}
} while (bFind);
ULONG CLobbyFrameDlg::FindProcessID(char *pProcessName)
{
ULONG process_id = 0;
HANDLE Snapshot;
Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 processListStr;
processListStr.dwSize = sizeof(PROCESSENTRY32);
BOOL return_value;
return_value = Process32First(Snapshot,&processListStr);
while(return_value)
{
if(strcmp(pProcessName, processListStr.szExeFile) == 0 )
{
process_id = processListStr.th32ProcessID;
break;
}
return_value = Process32Next(Snapshot, &processListStr);
}
CloseHandle( Snapshot );
return process_id;
}