TerminateProcess w2k and xp!
-
VC6.0 Hello, i have a question, how can i terminate a process from an another process? Ich my Situation i want start program b.exe from a.exe. But b.exe should start once a time! I do it with that: 1) First start b.exe: PROCESS_INFORMATION ProcInfo; STARTUPINFO startupInfo; memset(&startupInfo, 0, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); CreateProcess(NULL, // lpApplicationName "C:\\b.exe", // lpCommandLine NULL, // lpProcessAttributes NULL, // lpThreadAttributes NULL, // bInheritHandles NULL, // dwCreationFlags NULL, // lpEnvironment NULL, // lpCurrentDirectory &startupInfo, // lpStartupInfo ProcInfo); // lpProcessInformation 2) Second i check, wheter program is still activ HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pProcInfo->dwProcessId); if (handle!=NULL) { ... if programm b.exe activ terminate b.exe ... } else { ... start b.exe ... } 3) If programm b.exe active i terminate it and restart it I do it with this code: TerminateProcess(m_pProcInfo->hProcess, 0); Now i got back to step 1: This works fine in w2k, but in xp step 2 doesn't work. The handle is always not NULL. What is wrong? Give's a better way to do that? Thanks Chris Student
-
VC6.0 Hello, i have a question, how can i terminate a process from an another process? Ich my Situation i want start program b.exe from a.exe. But b.exe should start once a time! I do it with that: 1) First start b.exe: PROCESS_INFORMATION ProcInfo; STARTUPINFO startupInfo; memset(&startupInfo, 0, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); CreateProcess(NULL, // lpApplicationName "C:\\b.exe", // lpCommandLine NULL, // lpProcessAttributes NULL, // lpThreadAttributes NULL, // bInheritHandles NULL, // dwCreationFlags NULL, // lpEnvironment NULL, // lpCurrentDirectory &startupInfo, // lpStartupInfo ProcInfo); // lpProcessInformation 2) Second i check, wheter program is still activ HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pProcInfo->dwProcessId); if (handle!=NULL) { ... if programm b.exe activ terminate b.exe ... } else { ... start b.exe ... } 3) If programm b.exe active i terminate it and restart it I do it with this code: TerminateProcess(m_pProcInfo->hProcess, 0); Now i got back to step 1: This works fine in w2k, but in xp step 2 doesn't work. The handle is always not NULL. What is wrong? Give's a better way to do that? Thanks Chris Student
From the top of my head: maybe instead of PROCESS_ALL_ACCESS you should use PROCESS_TERMINATE? Tomasz Sowinski -- http://www.shooltz.com
-
From the top of my head: maybe instead of PROCESS_ALL_ACCESS you should use PROCESS_TERMINATE? Tomasz Sowinski -- http://www.shooltz.com
Hello Tomasz, thank you for your tip. I changed PROCESS_ALL_ACCESS to PROCESS_TERMINATE in OpenProcess(...). But i have the same effect as before. When i alredy had terminated the programm b.exe and it doesn't exist in the tast-manager. I do step 2 and the handle is alawy not NULL. But i see this effect only in XP. W2k show me NULL and I can start b.exe with createprocess. What do i wrong! Thanks Chris ceuba@gmx.net Student
-
Hello Tomasz, thank you for your tip. I changed PROCESS_ALL_ACCESS to PROCESS_TERMINATE in OpenProcess(...). But i have the same effect as before. When i alredy had terminated the programm b.exe and it doesn't exist in the tast-manager. I do step 2 and the handle is alawy not NULL. But i see this effect only in XP. W2k show me NULL and I can start b.exe with createprocess. What do i wrong! Thanks Chris ceuba@gmx.net Student
ceuba wrote: When i alredy had terminated the programm b.exe and it doesn't exist in the tast-manager. I do step 2 and the handle is alawy not NULL. But i see this effect only in XP. W2k show me NULL and I can start b.exe with createprocess. The process ID may be reused, so maybe you're getting the handle for other process? Anyway, since you're calling CreateProcess yourself, why don't you use another thread and WaitForSingleObject? Tomasz Sowinski -- http://www.shooltz.com