title: CreateProcess() launching child applications
body: <p>I want to launching a sub application from the main application using <code>CreateProcess</code> function with the following steps:</p>
  
  <ol>
  <li>launched a sub <code>.exe</code> program from the main without window for the sub program</li>
  <li>wait for <code>rand Sleep</code></li>
  <li>then terminate the sub application first then the main.</li>
  </ol>
  
  <p>In the following my example code for the above but the sub program running with window(in this case NotePad) and i can't terminate the sub program.  </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;windows.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;strsafe.h&gt;
  #include &lt;direct.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char* argv[])
  {   
  
  HWND                hWnd;
  STARTUPINFO         sInfo;
  PROCESS_INFORMATION pInfo;
  
  ZeroMemory(&amp;sInfo, sizeof(sInfo));
  sInfo.cb = sizeof(sInfo);
  ZeroMemory(&amp;pInfo, sizeof(pInfo));
  
  if (CreateProcess("C:\\WINDOWS\\System32\\notepad.exe", NULL, NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &amp;sInfo, &amp;pInfo))
  {
      printf("Sleeping 100ms...\n");
      Sleep(100);
  
      DWORD dwExitCode;
      GetExitCodeProcess(pInfo.hProcess, &amp;dwExitCode);
  
      CloseHandle(pInfo.hThread);
      CloseHandle(pInfo.hProcess);
  
      }
  
  system("pause");
  
  return 0;
  
   }
  </code></pre>