title: Start the process stopped with CreatEvent
body: <p>I am trying to write a program to get the processes information. My program uses createEvent to check if any process is stopped? If the process stops, the program will call and restart it.
      For project1 and project2 are any two projects. I wish when the program ran, if one of the two projects stopped, the program would call them back. </p>
  
  <pre><code>#include "stdafx.h"
  #include&lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;time.h&gt;
  
  using namespace std;
  
  HANDLE eventP1;
  HANDLE eventP2;
  HANDLE RunProcess(TCHAR* pszPath)
  {
      PROCESS_INFORMATION procInf;
      STARTUPINFO startInf;
      memset(&amp;procInf, 0, sizeof(procInf));
      memset(&amp;startInf, 0, sizeof(startInf));
  
      BOOL result;
      result = CreateProcess(pszPath, NULL, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &amp;startInf, &amp;procInf);
      if (result == FALSE)
      {
      cout &lt;&lt; "Process creation failed!" &lt;&lt; endl;
      return 0;
      }
      else
      {
      CloseHandle(procInf.hThread);
      return procInf.hProcess;
      }
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  
  {
  HANDLE hEndEvents[2];
      DWORD dwRet;
      eventP1 = CreateEvent(NULL, TRUE, FALSE, _T("Global\\eventP1"));
      eventP2 = CreateEvent(NULL, TRUE, FALSE, _T("Global\\eventP2"));
  
  
      hEndEvents[0] = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("Global\\eventP1"));
      hEndEvents[1] = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("Global\\eventP2"));
  
      if (hEndEvents[0] == NULL || hEndEvents[1] == NULL)
      {
          cout &lt;&lt; "Open Event " &lt;&lt; endl;
          cout &lt;&lt; GetLastError() &lt;&lt; endl;
  
      }
  
      RunProcess(_T("D:\\Project_VuongDV\\VS2013\\DemoEventProcess\\Debug\\Project1.exe"));
      RunProcess(_T("D:\\Project_VuongDV\\VS2013\\DemoEventProcess\\Debug\\Project2.exe"));
  
      while (true)
      {
          dwRet = WaitForMultipleObjects(2, hEndEvents, FALSE, INFINITE);
          if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_OBJECT_0 + 1)
          {
              Sleep(100);
              ResetEvent(hEndEvents[0]);
              ResetEvent(hEndEvents[1]);
              cout &lt;&lt; "project1 and Project2 run" &lt;&lt; endl;
              SetEvent(hEndEvents[0]);
              SetEvent(hEndEvents[1]);
  
  
          }
  
          else
          {
              cout &lt;&lt; "WAIL FALSE" &lt;&lt; endl;
              cout &lt;&lt; "Thread error is" &lt;&lt; GetLastError() &lt;&lt; endl;
              RunProcess(_T("D:\\Project_VuongDV\\VS2013\\DemoEventProcess\\Debug\\Project1.exe"));
              RunProcess(_T("D:\\Project_VuongDV\\VS2013\\DemoEventProcess\\Debug\\Project2.exe"));
  
          }
  
      }
  
      CloseHandle(hEndEvents[1]);
      CloseHandle(hEndEvents[2]);
      system("pause");
      return 0;
  }
  </code></pre>