In the VC program How to end the system is running other processes (the process must have a window interface), in fact, very simple, as the following steps can be:
1. Obtain the handle of the process (obtained by using the FindWindow function);
2. Get process ID number (obtained by GetWindowThreadProcessId function);
3. Open the process, the first parameter in the OpenProcess function is set to Process_terminate, you can get the handle that handles the process;
4. Using the TerminateProcess function to end the process, set the second parameter of the function to 4.
The code is as follows:
End Process
int cstaticfunc::killprocess (LPCSTR pszclassname, LPCSTR
Pszwindowtitle)
{
HANDLE Hprocesshandle;
ULONG Nprocessid;
HWND Thewindow;
Thewindow =:: FindWindow (NULL, pszwindowtitle);
Method One:
:: GetWindowThreadProcessId (Thewindow, &nprocessid);
Hprocesshandle =:: OpenProcess (Process_terminate, FALSE,
NPROCESSID);
Return:: TerminateProcess (Hprocesshandle, 4);
Method Two:
return::P ostmessage (Thewindow, wm_close, NULL, NULL);
}
The START process only needs the CreateProcess function to complete, you need to pay attention to the function of several input parameters, the first parameter is
Start a new process
Method One:
int cstaticfunc::createnewprocess (LPCSTR pszexename)
{
Process_information Piprocinfogps;
Startupinfo Sistartupinfo;
Security_attributes saprocess, Sathread;
ZeroMemory (&sistartupinfo, sizeof (Sistartupinfo));
SISTARTUPINFO.CB = sizeof (Sistartupinfo);
saprocess.nlength = sizeof (saprocess);
Saprocess.lpsecuritydescriptor = NULL;
Saprocess.binherithandle = true;
sathread.nlength = sizeof (Sathread);
Sathread.lpsecuritydescriptor = NULL;
Sathread.binherithandle = true;
Return:: CreateProcess (NULL, (LPTSTR) Pszexename, &saprocess,
&sathread, False,
Create_default_error_mode, NULL, NULL,
&sistartupinfo, &piprocinfogps);
}
Method Two:
WinExec (lpCmdLine, ucmdshow);