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.

163 lines
4.5 KiB

  1. #include <windows.h>
  2. #include <wbemidl.h>
  3. #include <wbemint.h>
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include "mofcomp.h"
  7. static CONST WCHAR cszWmiLoadEventName[] = {L"WMI_SysEvent_LodCtr"};
  8. static CONST WCHAR cszWmiUnloadEventName[] = {L"WMI_SysEvent_UnLodCtr"};
  9. DWORD SignalWmiWithNewData (DWORD dwEventId)
  10. {
  11. HANDLE hEvent;
  12. DWORD dwStatus = ERROR_SUCCESS;
  13. LPWSTR szEventName = NULL;
  14. switch (dwEventId) {
  15. case WMI_LODCTR_EVENT:
  16. szEventName = (LPWSTR)cszWmiLoadEventName;
  17. break;
  18. case WMI_UNLODCTR_EVENT:
  19. szEventName = (LPWSTR)cszWmiUnloadEventName;
  20. break;
  21. default:
  22. dwStatus = ERROR_INVALID_PARAMETER;
  23. break;
  24. }
  25. if (dwStatus == ERROR_SUCCESS) {
  26. hEvent = OpenEventW (
  27. EVENT_MODIFY_STATE | SYNCHRONIZE,
  28. FALSE,
  29. szEventName);
  30. if (hEvent != NULL) {
  31. // set event
  32. SetEvent (hEvent);
  33. CloseHandle (hEvent);
  34. } else {
  35. dwStatus = GetLastError();
  36. }
  37. }
  38. return dwStatus;
  39. }
  40. DWORD LodctrCompileMofFile ( LPCWSTR szComputerName, LPCWSTR szMofFileName )
  41. {
  42. HRESULT hRes;
  43. IMofCompiler *pMofComp = NULL;
  44. DWORD dwReturn = ERROR_SUCCESS;
  45. WBEM_COMPILE_STATUS_INFO Info;
  46. WCHAR szLocalServerName[1024];
  47. LPWSTR szServerPath;
  48. hRes = CoInitializeEx (0, COINIT_MULTITHREADED);
  49. if (hRes == S_OK) {
  50. // open the COM interface to the mof compiler object
  51. hRes = CoCreateInstance(
  52. CLSID_MofCompiler,
  53. NULL,
  54. CLSCTX_INPROC_SERVER,
  55. IID_IMofCompiler,
  56. (LPVOID *)&pMofComp);
  57. if (hRes == S_OK) {
  58. // load mof
  59. assert (pMofComp != NULL);
  60. if (szComputerName == NULL) {
  61. szServerPath = NULL;
  62. } else {
  63. assert (lstrlenW(szComputerName) < MAX_PATH);
  64. lstrcpyW (szLocalServerName, szComputerName);
  65. lstrcatW (szLocalServerName, L"\\root\\default");
  66. szServerPath = &szLocalServerName[0];
  67. }
  68. hRes = pMofComp->CompileFile (
  69. (LPWSTR)szMofFileName,
  70. NULL, // load into namespace specified in MOF file
  71. NULL, // use default User
  72. NULL, // use default Authority
  73. NULL, // use default Password
  74. 0, // no options
  75. 0, // no class flags
  76. 0, // no instance flags
  77. &Info);
  78. if (hRes != S_OK) {
  79. dwReturn = (DWORD)Info.hRes;
  80. }
  81. // close COM interface
  82. pMofComp->Release();
  83. } else {
  84. dwReturn = (DWORD)hRes;
  85. }
  86. CoUninitialize();
  87. } else {
  88. dwReturn = (DWORD)hRes;
  89. }
  90. return dwReturn;
  91. }
  92. DWORD LodctrCompileMofBuffer ( LPCWSTR szComputerName, LPVOID pMofBuffer, DWORD dwBufSize )
  93. {
  94. HRESULT hRes;
  95. IMofCompiler *pMofComp = NULL;
  96. DWORD dwReturn = ERROR_SUCCESS;
  97. WBEM_COMPILE_STATUS_INFO Info;
  98. DBG_UNREFERENCED_PARAMETER (szComputerName);
  99. hRes = CoInitializeEx (0, COINIT_MULTITHREADED);
  100. if (hRes == S_OK) {
  101. // open the COM interface to the mof compiler object
  102. hRes = CoCreateInstance(
  103. CLSID_MofCompiler,
  104. NULL,
  105. CLSCTX_INPROC_SERVER,
  106. IID_IMofCompiler,
  107. (LPVOID *)&pMofComp);
  108. if (hRes == S_OK) {
  109. // load mof
  110. assert (pMofComp != NULL);
  111. hRes = pMofComp->CompileBuffer (
  112. dwBufSize,
  113. (LPBYTE) pMofBuffer,
  114. NULL, // load into Root\Default on local mashine
  115. NULL, // use default User
  116. NULL, // use default Authority
  117. NULL, // use default Password
  118. 0, // no options
  119. WBEM_FLAG_UPDATE_FORCE_MODE, // no class flags
  120. 0, // no instance flags
  121. &Info);
  122. if (hRes != S_OK) {
  123. // return the detailed error code
  124. dwReturn = (DWORD)Info.hRes;
  125. }
  126. // close COM interface
  127. pMofComp->Release();
  128. } else {
  129. dwReturn = (DWORD)hRes;
  130. }
  131. CoUninitialize();
  132. } else {
  133. dwReturn = (DWORD)hRes;
  134. }
  135. return dwReturn;
  136. }