Leaked source code of windows server 2003
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.

55 lines
1.3 KiB

  1. #include "precomp.h"
  2. #include "ProcKiller.h"
  3. // the only one we'll ever need
  4. CProcKillerTimer g_procKillerTimer;
  5. // terminate process
  6. void CProcKiller::Die()
  7. {
  8. bool bDoIt = true;
  9. DWORD exitCode;
  10. // sleazy attempt to ensure that the proc is still running when we try to kill it
  11. // proc could still terminate on its own in the interim.
  12. if (GetExitCodeProcess(m_hProc, &exitCode))
  13. bDoIt = (exitCode == STILL_ACTIVE);
  14. if (bDoIt)
  15. TerminateProcess(m_hProc, 1);
  16. CloseHandle(m_hProc);
  17. m_hProc = NULL;
  18. }
  19. // hVictim is a handle to a process
  20. // last meal is the scheduled execution date
  21. HRESULT CProcKillerTimer::ScheduleAssassination(HANDLE hVictim, FILETIME lastMeal)
  22. {
  23. HRESULT hr = WBEM_E_FAILED;
  24. CProcKiller* pKiller;
  25. // gotta dup the handle - caller may close it.
  26. HANDLE hMyHandle;
  27. if (DuplicateHandle(GetCurrentProcess(), hVictim, GetCurrentProcess(), &hMyHandle, 0, false, DUPLICATE_SAME_ACCESS))
  28. {
  29. if (pKiller = new CProcKiller(hMyHandle, lastMeal, m_pControl))
  30. {
  31. hr = CKillerTimer::ScheduleAssassination(pKiller);
  32. }
  33. else
  34. {
  35. // allocation failed
  36. CloseHandle(hMyHandle);
  37. hr = WBEM_E_OUT_OF_MEMORY;
  38. }
  39. }
  40. else
  41. {
  42. ERRORTRACE((LOG_ESS, "DuplicateHandle failed, 0x%08X\n", GetLastError()));
  43. }
  44. return hr;
  45. }