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. How to manipulate with processes from your app? Any help is appreciated

How to manipulate with processes from your app? Any help is appreciated

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpcsharpc++tools
5 Posts 3 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.
  • O Offline
    O Offline
    Oshtri Deka
    wrote on last edited by
    #1

    The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:

    void CFireAdder::StartService(void)
    {
    CString planBrowserPath;
    #ifdef DEBUG
    planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
    #else
    planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
    #endif

    planBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");

    TRACE("starting planbrowser... ");
    \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL);
    WaitForInputIdle(\_process,INFINITE);
    TRACE("... started\\n");
    

    }

    And this is little piece of code I've written for getting utility's window handle:

    HWND CFireAdder::getWindowHandle()
    {
    if(_process == (HANDLE) -1) return NULL;

    //if(\_windowHandle != NULL) return \_windowHandle;
    
    DWORD procID = GetProcessId(\_process);
    
    if(procID > 0){
            //:) I know it's ugly but I was in a hurry 
    	HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama");
    	//\_windowHandle = hw;
    	return hw;
    }
    \_process = (HANDLE) -1;
    return NULL;
    

    }

    I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.

    S T 2 Replies Last reply
    0
    • O Oshtri Deka

      The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:

      void CFireAdder::StartService(void)
      {
      CString planBrowserPath;
      #ifdef DEBUG
      planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
      #else
      planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
      #endif

      planBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");

      TRACE("starting planbrowser... ");
      \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL);
      WaitForInputIdle(\_process,INFINITE);
      TRACE("... started\\n");
      

      }

      And this is little piece of code I've written for getting utility's window handle:

      HWND CFireAdder::getWindowHandle()
      {
      if(_process == (HANDLE) -1) return NULL;

      //if(\_windowHandle != NULL) return \_windowHandle;
      
      DWORD procID = GetProcessId(\_process);
      
      if(procID > 0){
              //:) I know it's ugly but I was in a hurry 
      	HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama");
      	//\_windowHandle = hw;
      	return hw;
      }
      \_process = (HANDLE) -1;
      return NULL;
      

      }

      I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      You've got a process handle - you can use GetExitCodeProcess[^] to see if the process has termnated or not - GetExitCodeProcess returns TRUE and the output status is STILL_ACTIVE if the process is still there.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      O 1 Reply Last reply
      0
      • O Oshtri Deka

        The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:

        void CFireAdder::StartService(void)
        {
        CString planBrowserPath;
        #ifdef DEBUG
        planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
        #else
        planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
        #endif

        planBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");

        TRACE("starting planbrowser... ");
        \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL);
        WaitForInputIdle(\_process,INFINITE);
        TRACE("... started\\n");
        

        }

        And this is little piece of code I've written for getting utility's window handle:

        HWND CFireAdder::getWindowHandle()
        {
        if(_process == (HANDLE) -1) return NULL;

        //if(\_windowHandle != NULL) return \_windowHandle;
        
        DWORD procID = GetProcessId(\_process);
        
        if(procID > 0){
                //:) I know it's ugly but I was in a hurry 
        	HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama");
        	//\_windowHandle = hw;
        	return hw;
        }
        \_process = (HANDLE) -1;
        return NULL;
        

        }

        I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        try using IsWindow api

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        O 1 Reply Last reply
        0
        • S Stuart Dootson

          You've got a process handle - you can use GetExitCodeProcess[^] to see if the process has termnated or not - GetExitCodeProcess returns TRUE and the output status is STILL_ACTIVE if the process is still there.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          O Offline
          O Offline
          Oshtri Deka
          wrote on last edited by
          #4

          Thank you! It works as expected.

          1 Reply Last reply
          0
          • T ThatsAlok

            try using IsWindow api

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

            O Offline
            O Offline
            Oshtri Deka
            wrote on last edited by
            #5

            I'll try it later, so far above mentioned solution satisfies me.

            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