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.

75 lines
2.1 KiB

  1. #include "sacsvr.h"
  2. SERVICE_STATUS MyServiceStatus;
  3. SERVICE_STATUS_HANDLE MyServiceStatusHandle;
  4. VOID
  5. MyServiceCtrlHandler (
  6. DWORD Opcode
  7. )
  8. {
  9. DWORD status;
  10. switch (Opcode) {
  11. case SERVICE_CONTROL_PAUSE:
  12. MyServiceStatus.dwCurrentState = SERVICE_PAUSED;
  13. break;
  14. case SERVICE_CONTROL_CONTINUE:
  15. MyServiceStatus.dwCurrentState = SERVICE_RUNNING;
  16. break;
  17. case SERVICE_CONTROL_STOP:
  18. case SERVICE_CONTROL_SHUTDOWN:
  19. MyServiceStatus.dwWin32ExitCode = 0;
  20. MyServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
  21. MyServiceStatus.dwCheckPoint = 0;
  22. MyServiceStatus.dwWaitHint = 0;
  23. //
  24. // Notify the SCM that we are attempting to shutdown
  25. //
  26. if (!SetServiceStatus(MyServiceStatusHandle, &MyServiceStatus)) {
  27. status = GetLastError();
  28. SvcDebugOut(" [MY_SERVICE] SetServiceStatus error %ld\n",status);
  29. }
  30. //
  31. // Service specific code goes here
  32. //
  33. // <<begin>>
  34. SvcDebugOut(" [MY_SERVICE] Stopping MyService \n",0);
  35. Stop();
  36. SvcDebugOut(" [MY_SERVICE] Stopped MyService \n",0);
  37. // <<end>>
  38. //
  39. // Notify the SCM that we are shutdown
  40. //
  41. MyServiceStatus.dwWin32ExitCode = 0;
  42. MyServiceStatus.dwCurrentState = SERVICE_STOPPED;
  43. MyServiceStatus.dwCheckPoint = 0;
  44. MyServiceStatus.dwWaitHint = 0;
  45. SvcDebugOut(" [MY_SERVICE] Leaving MyService \n",0);
  46. break;
  47. case SERVICE_CONTROL_INTERROGATE:
  48. // Fall through to send current status.
  49. break;
  50. default:
  51. SvcDebugOut(" [MY_SERVICE] Unrecognized opcode %ld\n", Opcode);
  52. break;
  53. }
  54. // Send current status.
  55. if (!SetServiceStatus (MyServiceStatusHandle, &MyServiceStatus)) {
  56. status = GetLastError();
  57. SvcDebugOut(" [MY_SERVICE] SetServiceStatus error %ld\n",status);
  58. }
  59. return;
  60. }