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.

99 lines
2.6 KiB

  1. #include "precomp.h"
  2. #include <commain.h>
  3. #include <clsfac.h>
  4. #include <TChar.h>
  5. #include "ClassFac.h"
  6. #include "ScriptKiller.h"
  7. #include "script.h"
  8. #include "StrSafe.h"
  9. const CLSID CLSID_WbemActiveScriptConsumer =
  10. {0x266c72e7,0x62e8,0x11d1,{0xad,0x89,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
  11. class CMyServer : public CComServer
  12. {
  13. public:
  14. #ifdef ENABLE_REMOTING
  15. void RegisterMe(CLSID clsID, WCHAR* name)
  16. {
  17. WCHAR wcID[128];
  18. WCHAR szKeyName[128];
  19. HKEY hKey;
  20. // open/create registry entry under CLSID
  21. // not checking return codes of string functions when all sizes are known at compile time
  22. StringFromGUID2(clsID, wcID, 128);
  23. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\CLSID\\"));
  24. StringCchCatW(szKeyName, 128, wcID);
  25. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  26. // set AppID
  27. RegSetValueEx(hKey, L"AppID", 0, REG_SZ, (BYTE*)wcID, 2*(wcslen(wcID) +1));
  28. RegCloseKey(hKey);
  29. // make appID entry w/ DLLSurrogate value
  30. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\APPID\\"));
  31. StringCchCatW(szKeyName, 128, wcID);
  32. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  33. // and a nice name
  34. RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)name, 2*(wcslen(name) +1));
  35. RegCloseKey(hKey);
  36. }
  37. virtual void Register()
  38. {
  39. RegisterMe(CLSID_WbemActiveScriptConsumer, L"Microsoft WBEM Active Scripting Event Consumer Provider");
  40. }
  41. void UnregisterMe(CLSID clsID)
  42. {
  43. WCHAR wcID[128];
  44. HKEY hKey;
  45. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\APPID\\"), &hKey))
  46. {
  47. if (0 != StringFromGUID2(clsID, wcID, 128))
  48. {
  49. RegDeleteKey(hKey, wcID);
  50. }
  51. RegCloseKey(hKey);
  52. }
  53. }
  54. virtual void Unregister()
  55. {
  56. UnregisterMe(CLSID_WbemActiveScriptConsumer);
  57. }
  58. #endif // ENABLE_REMOTING
  59. protected:
  60. HRESULT Initialize()
  61. {
  62. g_scriptKillerTimer.Initialize(GetLifeControl());
  63. WMIScriptClassFactory* pFact;
  64. pFact = new WMIScriptClassFactory(GetLifeControl());
  65. if ( pFact == NULL )
  66. {
  67. return WBEM_E_OUT_OF_MEMORY;
  68. }
  69. HRESULT hr;
  70. hr = AddClassInfo( CLSID_WbemActiveScriptConsumer,
  71. pFact,
  72. _T("Active Scripting Event Consumer Provider"),
  73. TRUE );
  74. if ( FAILED(hr) )
  75. return hr;
  76. return S_OK;
  77. }
  78. } g_Server;