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.

156 lines
5.0 KiB

  1. #include "precomp.h"
  2. #include <commain.h>
  3. #include <clsfac.h>
  4. #include "logfile.h"
  5. #include "cmdline.h"
  6. #include "evtlog.h"
  7. #include "ProcKiller.h"
  8. #include <tchar.h>
  9. const CLSID CLSID_WbemLogFileConsumer =
  10. {0x266c72d4,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  11. const CLSID CLSID_WbemCommandLineConsumer =
  12. {0x266c72e5,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  13. const CLSID CLSID_WbemNTEventLogConsumer =
  14. {0x266c72e6,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  15. #ifdef INCLUDE_NON_PULSAR
  16. const CLSID CLSID_WbemPerformanceConsumer =
  17. {0x266c72f8,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  18. const CLSID CLSID_WbemMsgBoxConsumer =
  19. {0x266c72d2,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  20. // {C7A3A54A-0250-11d3-9CD1-00105A1F4801}
  21. const CLSID CLSID_WbemPagerConsumer =
  22. { 0xc7a3a54a, 0x250, 0x11d3, { 0x9c, 0xd1, 0x0, 0x10, 0x5a, 0x1f, 0x48, 0x1 } };
  23. #endif
  24. //const CLSID CLSID_WbemEmailConsumer =
  25. // {0x266c72d3,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  26. class CMyServer : public CComServer
  27. {
  28. public:
  29. #ifdef ENABLE_REMOTING
  30. void RegisterMe(CLSID clsID, WCHAR* name)
  31. {
  32. WCHAR wcID[128];
  33. WCHAR szKeyName[128];
  34. HKEY hKey;
  35. // open/create registry entry under CLSID
  36. StringFromGUID2(clsID, wcID, 128);
  37. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\CLSID\\"));
  38. StringCchCatW(szKeyName, 128, wcID);
  39. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  40. // set AppID
  41. RegSetValueEx(hKey, L"AppID", 0, REG_SZ, (BYTE*)wcID, 2*(wcslen(wcID) +1));
  42. RegCloseKey(hKey);
  43. // make appID entry w/ DLLSurrogate value
  44. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\APPID\\"));
  45. StringCchCatW(szKeyName, 128, wcID);
  46. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  47. RegSetValueEx(hKey, L"DllSurrogate", 0, REG_SZ, (BYTE*)L"\0", 2);
  48. // and a nice name
  49. RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)name, 2*(wcslen(name) +1));
  50. RegCloseKey(hKey);
  51. }
  52. // provider server specific registration
  53. virtual void Register()
  54. {
  55. RegisterMe(CLSID_WbemLogFileConsumer, L"Microsoft WBEM Log File Event Consumer Provider");
  56. RegisterMe(CLSID_WbemCommandLineConsumer, L"Microsoft WBEM Command Line Event Consumer Provider");
  57. RegisterMe(CLSID_WbemNTEventLogConsumer, L"Microsoft WBEM NT Event Log Event Consumer Provider");
  58. #ifdef INCLUDE_NON_PULSAR
  59. // NOTE: Of the non-pulsar componenets,
  60. // Only the pager consumer is registered for remote activation
  61. // MessageBox & Performance consumer are not
  62. RegisterMe(CLSID_WbemPagerConsumer, L"Microsoft WBEM Pager Event Consumer Provider");
  63. #endif // INCLUDE_NON_PULSAR
  64. }
  65. void UnregisterMe(CLSID clsID)
  66. {
  67. WCHAR wcID[128];
  68. HKEY hKey;
  69. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\APPID\\"), &hKey))
  70. {
  71. if (0 != StringFromGUID2(clsID, wcID, 128))
  72. {
  73. RegDeleteKey(hKey, wcID);
  74. }
  75. RegCloseKey(hKey);
  76. }
  77. }
  78. virtual void Unregister()
  79. {
  80. UnregisterMe(CLSID_WbemLogFileConsumer);
  81. UnregisterMe(CLSID_WbemCommandLineConsumer);
  82. UnregisterMe(CLSID_WbemNTEventLogConsumer);
  83. #ifdef INCLUDE_NON_PULSAR
  84. // NOTE: Of the non-pulsar componenets,
  85. // Only the pager consumer is registered for remote activation
  86. // MessageBox & Performance consumer are not
  87. UnregisterMe(CLSID_WbemPagerConsumer);
  88. #endif // INCLUDE_NON_PULSAR
  89. }
  90. #endif //ENABLE_REMOTING
  91. protected:
  92. HRESULT Initialize()
  93. {
  94. g_procKillerTimer.Initialize(GetLifeControl());
  95. AddClassInfo(CLSID_WbemLogFileConsumer,
  96. new CClassFactory<CLogFileConsumer>(GetLifeControl()),
  97. _T("Log File Event Consumer Provider"), TRUE);
  98. AddClassInfo(CLSID_WbemCommandLineConsumer,
  99. new CClassFactory<CCommandLineConsumer>(GetLifeControl()),
  100. _T("Command Line Event Consumer Provider"), TRUE);
  101. AddClassInfo(CLSID_WbemNTEventLogConsumer,
  102. new CClassFactory<CEventLogConsumer>(GetLifeControl()),
  103. _T("NT Event Log Event Consumer Provider"), TRUE);
  104. #ifdef INCLUDE_NON_PULSAR
  105. AddClassInfo(CLSID_WbemMsgBoxConsumer,
  106. new CClassFactory<CMsgBoxConsumer>(GetLifeControl()),
  107. "Message Box Event Consumer Provider", TRUE);
  108. AddClassInfo(CLSID_WbemPerformanceConsumer,
  109. new CClassFactory<CPerfConsumer>(GetLifeControl()),
  110. "Performance measurement Event Consumer Provider", TRUE);
  111. AddClassInfo(CLSID_WbemPagerConsumer,
  112. new CClassFactory<CPagerConsumer>(GetLifeControl()),
  113. "Pager Event Consumer Provider", TRUE);
  114. #endif // INCLUDE_NON_PULSAR
  115. return S_OK;
  116. }
  117. } g_Server;