CreateProcess and TerminateProcess
Hello NG,
I want to kill a process that I created with CreateProces . This is what I
do:
char* szProgramm = "C:\\Windows\\System32\\mspaint.exe";
STARTUPINFO m_si;
PROCESS_INFORMATION m_pi;
BOOL bRet = CreateProcess( NULL, // No module name (use command line).
szProgramm, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&m_si, // Pointer to STARTUPINFO structure.
&m_pi ); // Pointer to PROCESS_INFORMATION structure.
if (!bRet)
{
if (m_pi.hProcess) CloseHandle( m_pi.hProcess );
if (m_pi.hThread) CloseHandle( m_pi.hThread );
}
// now MS Paint has started
// ...
// after some time I want to kill MS Paint again:
if (m_pi.hProcess) CloseHandle( m_pi.hProcess );
if (m_pi.hThread) CloseHandle( m_pi.hThread );
if (m_pi.hProcess) TerminateProcess(m_pi.hProcess,0);
But the process is not terminated/killed.
How can I kill the process?
Thanks for help,
Guido