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.

120 lines
4.1 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_ProgramGroup.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_ProgramGroup class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. Ghim-Sim Chua (gschua) 05/02/99
  11. - Modified code to use CopyProperty function
  12. - Use CComBSTR instead of USES_CONVERSION
  13. ********************************************************************/
  14. #include "pchealth.h"
  15. #include "PCH_ProgramGroup.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // tracing stuff
  18. #ifdef THIS_FILE
  19. #undef THIS_FILE
  20. #endif
  21. static char __szTraceSourceFile[] = __FILE__;
  22. #define THIS_FILE __szTraceSourceFile
  23. #define TRACE_ID DCID_PROGRAMGROUP
  24. CPCH_ProgramGroup MyPCH_ProgramGroupSet (PROVIDER_NAME_PCH_PROGRAMGROUP, PCH_NAMESPACE) ;
  25. // Property names
  26. //===============
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pGroupName = L"GroupName" ;
  30. const static WCHAR* pName = L"Name" ;
  31. const static WCHAR* pUsername = L"Username" ;
  32. /*****************************************************************************
  33. *
  34. * FUNCTION : CPCH_ProgramGroup::EnumerateInstances
  35. *
  36. * DESCRIPTION : Returns all the instances of this class.
  37. *
  38. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  39. * A long that contains the flags described in
  40. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  41. * flags are handled by (and filtered out by) WinMgmt:
  42. * WBEM_FLAG_DEEP
  43. * WBEM_FLAG_SHALLOW
  44. * WBEM_FLAG_RETURN_IMMEDIATELY
  45. * WBEM_FLAG_FORWARD_ONLY
  46. * WBEM_FLAG_BIDIRECTIONAL
  47. *
  48. * RETURNS : WBEM_S_NO_ERROR if successful
  49. *
  50. * COMMENTS : All instances on the machine are returned here.
  51. * If there are no instances, WBEM_S_NO_ERROR is returned.
  52. * It is not an error to have no instances.
  53. *
  54. *****************************************************************************/
  55. HRESULT CPCH_ProgramGroup::EnumerateInstances(
  56. MethodContext* pMethodContext,
  57. long lFlags
  58. )
  59. {
  60. TraceFunctEnter("CPCH_ProgramGroup::EnumerateInstances");
  61. HRESULT hRes = WBEM_S_NO_ERROR;
  62. REFPTRCOLLECTION_POSITION posList;
  63. CComPtr<IEnumWbemClassObject> pEnumInst;
  64. IWbemClassObjectPtr pObj;
  65. ULONG ulRetVal;
  66. // Get the date and time
  67. SYSTEMTIME stUTCTime;
  68. GetSystemTime(&stUTCTime);
  69. // Execute the query
  70. hRes = ExecWQLQuery(&pEnumInst, CComBSTR("select GroupName, Name, UserName from Win32_ProgramGroup"));
  71. if (FAILED(hRes))
  72. goto END;
  73. // enumerate the instances from win32_CodecFile
  74. while (WBEM_S_NO_ERROR == pEnumInst->Next(WBEM_INFINITE, 1, &pObj, &ulRetVal))
  75. {
  76. // Create a new instance based on the passed-in MethodContext. If this fails,
  77. // we don't need to check for a null pointer because it throws an exception.
  78. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  79. CComVariant varValue;
  80. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  81. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  82. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  83. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  84. (void)CopyProperty(pObj, L"GroupName", pInstance, pGroupName);
  85. (void)CopyProperty(pObj, L"Name", pInstance, pName);
  86. (void)CopyProperty(pObj, L"UserName", pInstance, pUsername);
  87. hRes = pInstance->Commit();
  88. if (FAILED(hRes))
  89. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  90. }
  91. END:
  92. TraceFunctLeave();
  93. return hRes ;
  94. }