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.

100 lines
2.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. srvmain.c
  5. Abstract:
  6. This routine is a service stub for WDM WMI service. This is for
  7. backward compatibility with Windows 2000 where other services
  8. were dependent on WDM WMI Service.
  9. Author:
  10. 27-Mar-2001 Melur Raghuraman
  11. Revision History:
  12. --*/
  13. #include "wmiump.h"
  14. SERVICE_STATUS_HANDLE WmiServiceStatusHandle;
  15. SERVICE_STATUS WmiServiceStatus;
  16. HANDLE WmipTerminationEvent;
  17. VOID
  18. WmipUpdateServiceStatus (
  19. DWORD dwState
  20. )
  21. {
  22. WmipAssert(WmiServiceStatusHandle);
  23. WmiServiceStatus.dwCurrentState = dwState;
  24. SetServiceStatus (WmiServiceStatusHandle, &WmiServiceStatus);
  25. }
  26. VOID
  27. WINAPI
  28. WmiServiceCtrlHandler (
  29. DWORD dwOpcode)
  30. {
  31. switch (dwOpcode)
  32. {
  33. case SERVICE_CONTROL_STOP:
  34. WmipUpdateServiceStatus (SERVICE_STOP_PENDING);
  35. NtSetEvent( WmipTerminationEvent, NULL );
  36. break;
  37. case SERVICE_CONTROL_PAUSE:
  38. case SERVICE_CONTROL_CONTINUE:
  39. case SERVICE_CONTROL_INTERROGATE:
  40. case SERVICE_CONTROL_SHUTDOWN:
  41. default:
  42. WmipAssert (WmiServiceStatusHandle);
  43. SetServiceStatus (WmiServiceStatusHandle, &WmiServiceStatus);
  44. break;
  45. }
  46. }
  47. VOID
  48. WINAPI
  49. WdmWmiServiceMain (
  50. DWORD argc,
  51. PWSTR argv[])
  52. {
  53. NTSTATUS Status;
  54. RtlZeroMemory (&WmiServiceStatus, sizeof(WmiServiceStatus));
  55. WmiServiceStatus.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
  56. WmiServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
  57. WmiServiceStatusHandle = RegisterServiceCtrlHandler (L"Wmi", WmiServiceCtrlHandler);
  58. if (WmiServiceStatusHandle)
  59. {
  60. WmipUpdateServiceStatus (SERVICE_RUNNING);
  61. Status = NtCreateEvent( &WmipTerminationEvent,
  62. EVENT_ALL_ACCESS,
  63. NULL,
  64. SynchronizationEvent,
  65. FALSE
  66. );
  67. if (!NT_SUCCESS(Status) ) {
  68. WmipDebugPrint(("WMI: CreateEvent Failed %d\n", GetLastError() ));
  69. }
  70. else {
  71. Status = NtWaitForSingleObject( WmipTerminationEvent, FALSE, NULL);
  72. }
  73. WmipUpdateServiceStatus (SERVICE_STOPPED);
  74. }
  75. else
  76. {
  77. WmipDebugPrint( ( "WMI: RegisterServiceCtrlHandler failed %d\n", GetLastError() ));
  78. }
  79. }