In the VC program, how to end other processes that are running in the system (the process must have a window interface) is actually very simple, just follow the steps below:
1. Obtain the Process Handle (obtained using the findwindow function );
2. Get the process ID (obtained using the getwindowthreadprocessid function );
3. Open the process and set the first parameter in the OpenProcess function to process_terminate to obtain the handle to process the process;
4. Use the terminateprocess function to end the process and set the second parameter of the function to 4.
The Code is as follows:
// End the process
Int cstaticfunc: killprocess (lpcstr pszclassname, lpcstr
Pszwindowtitle)
{
Handle hprocesshandle;
Ulong nprocessid;
Hwnd thewindow;
Thewindow =: findwindow (null, pszwindowtitle );
/// Method 1:
: Getwindowthreadprocessid (thewindow, & nprocessid );
Hprocesshandle =: OpenProcess (process_terminate, false,
Nprocessid );
Return: terminateprocess (hprocesshandle, 4 );
/// Method 2:
Return: postmessage (thewindow, wm_close, null, null );
}
To start a process, you only need the CreateProcess function to complete the process. Note the input parameters of this function. The first parameter is
// Start a new process
/// Method 1:
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 2:
Winexec (Lpcmdline,Ucmdshow);