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.

199 lines
4.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2000, Microsoft Corporation, All rights reserved
  3. //
  4. // NCEvents.h
  5. //
  6. // This file is the interface to using non-COM events.
  7. //
  8. #include "precomp.hxx"
  9. #include "NCObjAPI.h"
  10. #include "NCEvents.h"
  11. #define NUM_NC_EVENTS NCE_InvalidIndex
  12. #define MAX_BUFFER_SIZE 32000
  13. #define SEND_LATENCY 100
  14. static HANDLE g_hConnection;
  15. HANDLE g_hNCEvents[NUM_NC_EVENTS];
  16. LPCWSTR szEventSetup[NUM_NC_EVENTS * 2] =
  17. {
  18. L"MSFT_NetBadAccount",
  19. L"",
  20. L"MSFT_NetCallToFunctionFailed",
  21. L"FunctionName!s! Error!u!",
  22. L"MSFT_NetCallToFunctionFailedII",
  23. L"FunctionName!s! Argument!s! Error!u!",
  24. L"MSFT_NetFirstLogonFailed",
  25. L"Error!u!",
  26. L"MSFT_NetRevertedToLastKnownGood",
  27. L"",
  28. L"MSFT_NetConnectionTimeout",
  29. L"Milliseconds!u! Service!s!",
  30. L"MSFT_NetReadfileTimeout",
  31. L"Milliseconds!u!",
  32. L"MSFT_NetTransactTimeout",
  33. L"Milliseconds!u! Service!s!",
  34. L"MSFT_NetTransactInvalid",
  35. L"",
  36. L"MSFT_NetServiceCrash",
  37. L"Service!s! TimesFailed!u! ActionDelay!u! ActionType!u! Action!s!",
  38. L"MSFT_NetServiceCrashNoAction",
  39. L"Service!s! TimesFailed!u!",
  40. L"MSFT_NetServiceNotInteractive",
  41. L"Service!s!",
  42. L"MSFT_NetServiceRecoveryFailed",
  43. L"ActionType!u! Action!s! Service!s! Error!u!",
  44. L"MSFT_NetInvalidDriverDependency",
  45. L"Driver!s!",
  46. L"MSFT_NetServiceStartFailed",
  47. L"Service!s! Error!u!",
  48. L"MSFT_NetCircularDependencyDemand",
  49. L"Service!s!",
  50. L"MSFT_NetCircularDependencyAuto",
  51. L"",
  52. L"MSFT_NetServiceStartFailedNone",
  53. L"Service!s! NonExistingService!s!",
  54. L"MSFT_NetServiceStartFailedII",
  55. L"Service!s! DependedOnService!s! Error!u!",
  56. L"MSFT_NetDependOnLaterService",
  57. L"Service!s!",
  58. L"MSFT_NetServiceStartFailedGroup",
  59. L"Service!s! Group!s!",
  60. L"MSFT_NetDependOnLaterGroup",
  61. L"Service!s!",
  62. L"MSFT_NetServiceStartHung",
  63. L"Service!s!",
  64. L"MSFT_NetSevereServiceFailed",
  65. L"Service!s!",
  66. L"MSFT_NetTakeOwnership",
  67. L"RegistryKey!s!",
  68. L"MSFT_NetBadServiceState",
  69. L"Service!s! State!u!",
  70. L"MSFT_NetServiceExitFailed",
  71. L"Service!s! Error!u!",
  72. L"MSFT_NetServiceExitFailedSpecific",
  73. L"Service!s! Error!u!",
  74. L"MSFT_NetBootSystemDriversFailed",
  75. L"DriverList!s!",
  76. L"MSFT_NetServiceControlSuccess",
  77. L"Service!s! Control!s! sid!s!",
  78. L"MSFT_NetServiceStatusSuccess",
  79. L"Service!s! Control!s!",
  80. L"MSFT_NetServiceConfigBackoutFailed",
  81. L"Service!s! ConfigField!s!",
  82. L"MSFT_NetFirstLogonFailedII",
  83. L"Service!s! Account!s! Error!u!",
  84. L"MSFT_NetServiceDifferentPIDConnected",
  85. L"Service!s! ExpectedPID!u! ActualPID!u!"
  86. };
  87. #define SCM_PROV_NAME L"SCM Event Provider"
  88. BOOL InitNCEvents()
  89. {
  90. BOOL bRet;
  91. g_hConnection =
  92. WmiEventSourceConnect(
  93. L"root\\cimv2",
  94. SCM_PROV_NAME,
  95. TRUE,
  96. MAX_BUFFER_SIZE,
  97. SEND_LATENCY,
  98. NULL,
  99. NULL);
  100. if (g_hConnection)
  101. {
  102. for (int i = 0; i < NUM_NC_EVENTS; i++)
  103. {
  104. g_hNCEvents[i] =
  105. WmiCreateObjectWithFormat(
  106. g_hConnection,
  107. szEventSetup[i * 2],
  108. WMI_CREATEOBJ_LOCKABLE,
  109. szEventSetup[i * 2 + 1]);
  110. if (!g_hNCEvents[i])
  111. break;
  112. }
  113. bRet = i == NUM_NC_EVENTS;
  114. }
  115. else
  116. bRet = FALSE;
  117. return bRet;
  118. }
  119. void DeinitNCEvents()
  120. {
  121. for (int i = 0; i < NUM_NC_EVENTS; i++)
  122. {
  123. if (g_hNCEvents[i])
  124. WmiDestroyObject(g_hNCEvents[i]);
  125. }
  126. if (g_hConnection)
  127. WmiEventSourceDisconnect(g_hConnection);
  128. }
  129. BOOL WINAPI NCFireEvent(DWORD dwIndex, ...)
  130. {
  131. va_list list;
  132. BOOL bRet;
  133. va_start(list, dwIndex);
  134. bRet =
  135. WmiSetAndCommitObject(
  136. g_hNCEvents[dwIndex],
  137. WMI_SENDCOMMIT_SET_NOT_REQUIRED | WMI_USE_VA_LIST,
  138. &list);
  139. return bRet;
  140. }
  141. BOOL WINAPI NCIsEventActive(DWORD dwIndex)
  142. {
  143. return WmiIsObjectActive(g_hNCEvents[dwIndex]);
  144. }