Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
901 B

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include "utils.h"
  9. DWORD WaitOnProcess(char *szExe, char *szParams, bool bHidden/*=true*/, bool bWait/*=true*/)
  10. {
  11. STARTUPINFO si;
  12. PROCESS_INFORMATION pi;
  13. BOOL bRet;
  14. DWORD dwExitCode=STILL_ACTIVE;
  15. ZeroMemory(&si,sizeof(si));
  16. si.cb=sizeof(si);
  17. bRet=CreateProcess(szExe,szParams,NULL,NULL,NULL,
  18. ((bHidden)?DETACHED_PROCESS:CREATE_NEW_CONSOLE),NULL,NULL,&si,&pi);
  19. //wait until done
  20. //===============
  21. if (bRet && bWait)
  22. {
  23. while(dwExitCode==STILL_ACTIVE)
  24. {
  25. Sleep(100); //don't be a pig
  26. GetExitCodeProcess(pi.hProcess,&dwExitCode);
  27. }
  28. CloseHandle(pi.hThread);
  29. CloseHandle(pi.hProcess);
  30. }
  31. else
  32. {
  33. dwExitCode=(bRet)?0:1;
  34. }
  35. return dwExitCode;
  36. }