In VCProgramHow to end other processes that are running in the system (the process must have a window interface) is actually very simple, 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.
CodeAs follows:
// End the process
Int cstaticfunc: 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 );
}
////// // The process still exists in the task manager after your program exits. This function can be called to end.
Int cstaticfunc: killprocess (lpcstr pszwindowtitle)
{
/////////////// Pszwindowtitle: your own program name
////////////// Call this function directly when you end your program (lpcstr pname ("your program name "))
Handle hprocesshandle;
Ulong nprocessid;
Hwnd thewindow;
Thewindow =: findwindow (null, pszwindowtitle );
: Getwindowthreadprocessid (thewindow, & nprocessid );
Hprocesshandle =: OpenProcess (process_terminate, false, nprocessid );
Return: terminateprocess (hprocesshandle, 4 );
}
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
int cstaticfunc: createnewprocess (lpcstr pszexename)
{< br> process_information piprocinfogps;
startupinfo sistartupinfo;
specify 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 );
}