CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    5

    Running AND tracking other executables from C++

    So I've got some code that I'm writing that I want to call another .exe file. I don't have access to the source of that .exe and there is no dll form of it so I'm stuck with what I've got. So I want to make a call to run that code (which I do know how to do).

    But I need the code I'm writing to wait for the other executable to be done running before it continues (and unfortunately there's a LOT of variation in its run time). Is there any ways to use API calls to cause some sort of wait loop to wait for another executable to be done?

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Running AND tracking other executables from C++

    Use ShellExecuteEx with SHELLEXECUTEINFO set to return the handle to the running app, then wait on that handle:

    Code:
      SHELLEXECUTEINFO sei;
    
      memset(&sei,0,sizeof(SHELLEXECUTEINFO));
      sei.cbSize=sizeof(SHELLEXECUTEINFO);
      sei.fMask=SEE_MASK_NOCLOSEPROCESS;
      sei.lpVerb=L"OPEN";
      sei.lpFile=L"C:\\Program Files (x86)\\MyProgram\\MyProgram.exe";
      sei.lpDirectory=L"C:\\Program Files (x86)\\MyProgram\\";
      sei.nShow=1;
    
      ShellExecuteEx(&sei);
      WaitForSingleObject(sei.hProcess,INFINITE);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured