Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. TerminateProcess w2k and xp!

TerminateProcess w2k and xp!

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ceuba
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • C ceuba

      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

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      From the top of my head: maybe instead of PROCESS_ALL_ACCESS you should use PROCESS_TERMINATE? Tomasz Sowinski -- http://www.shooltz.com

      C 1 Reply Last reply
      0
      • T Tomasz Sowinski

        From the top of my head: maybe instead of PROCESS_ALL_ACCESS you should use PROCESS_TERMINATE? Tomasz Sowinski -- http://www.shooltz.com

        C Offline
        C Offline
        ceuba
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • C ceuba

          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

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups