This article describes the VC using TerminateProcess to end the process of the method to share for everyone to reference. The implementation methods are as follows:
Copy Code code as follows:
int killprocess (LPCSTR pszclassname, LPCSTR
Pszwindowtitle)
{
HANDLE Hprocesshandle;
ULONG Nprocessid;
HWND Thewindow;
Thewindow =:: FindWindow (NULL, pszwindowtitle);
:: GetWindowThreadProcessId (Thewindow, &nprocessid);
Hprocesshandle =:: OpenProcess (Process_terminate, FALSE,
NPROCESSID);
Return:: TerminateProcess (Hprocesshandle, 4);
}
void Czxdlg::onok ()
{
Todo:add Extra Validation here
Cdialog::onok ();
KillProcess ("Radmin.exe", "Radmin Viewer")
}
void Czxdlg::onbutton1 ()
{
HANDLE hSnapShot =:: CreateToolhelp32Snapshot (th32cs_snapprocess,0);
if (hsnapshot = 0)
Return
PROCESSENTRY32 Thepe;
thepe.dwsize = sizeof (PROCESSENTRY32);
Traversing the first system process that is running
BOOL Status = Process32First (Hsnapshot,&thepe);
BOOL Bhaveflag = false;
DWORD ProcessID = 0;
while (Status)
{
Traversing the next system process that is running
Status = Process32Next (Hsnapshot,&thepe);
CString Jincheng = "Qq.exe";
Jincheng. Makelower ();
Find the appropriate process **.exe
if (0 = = _tcscmp (thepe.szexefile,_t (Jincheng))
{
Bhaveflag = true;
ProcessID = Thepe.th32processid;
Ends the specified process ProcessID
if (! TerminateProcess (openprocess, process_terminate| | PROCESS_QUERY_INFORMATION,FALSE,PROCESSID), 0)
{
AfxMessageBox ("Unable to terminate the specified process!") ", Mb_iconwarning| | MB_OK);
}
Break
}
}
CloseHandle (hSnapShot);
}
Your own improved code is as follows:
Copy Code code as follows:
void Kill (CString Jin)
{
HANDLE hSnapShot =:: CreateToolhelp32Snapshot (th32cs_snapprocess,0);
if (hsnapshot = 0)
Return
PROCESSENTRY32 Thepe;
thepe.dwsize = sizeof (PROCESSENTRY32);
Traversing the first system process that is running
BOOL Status = Process32First (Hsnapshot,&thepe);
BOOL Bhaveflag = false;
DWORD ProcessID = 0;
while (Status)
{
Traversing the next system process that is running
Status = Process32Next (Hsnapshot,&thepe);
CString Jincheng;
Jincheng=thepe.szexefile;
Jincheng. Makelower ();
Find the appropriate process **.exe
if (Jincheng = Jin)
{
Bhaveflag = true;
ProcessID = Thepe.th32processid;
AfxMessageBox (Thepe.szexefile,mb_iconwarning| | MB_OK);
Ends the specified process ProcessID
if (! TerminateProcess (openprocess, process_terminate| | PROCESS_QUERY_INFORMATION,FALSE,PROCESSID), 0)
{
AfxMessageBox ("Unable to terminate the specified process!") ", Mb_iconwarning| | MB_OK);
}
Break
}
}
CloseHandle (hSnapShot);
}
I hope this article on the VC program for everyone to help.