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.

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