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.

122 lines
3.9 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_Device.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_Device class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. ********************************************************************/
  11. #include "pchealth.h"
  12. #include "PCH_Device.h"
  13. // #include "confgmgr.h"
  14. // #include <cregcls.h>
  15. /////////////////////////////////////////////////////////////////////////////
  16. // tracing stuff
  17. #ifdef THIS_FILE
  18. #undef THIS_FILE
  19. #endif
  20. static char __szTraceSourceFile[] = __FILE__;
  21. #define THIS_FILE __szTraceSourceFile
  22. #define TRACE_ID DCID_DEVICE
  23. CPCH_Device MyPCH_DeviceSet (PROVIDER_NAME_PCH_DEVICE, PCH_NAMESPACE) ;
  24. // Property names
  25. //===============
  26. const static WCHAR* pCategory = L"Category" ;
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pDescription = L"Description" ;
  30. const static WCHAR* pDriveLetter = L"DriveLetter" ;
  31. const static WCHAR* pHWRevision = L"HWRevision" ;
  32. const static WCHAR* pName = L"Name" ;
  33. const static WCHAR* pRegkey = L"Regkey" ;
  34. /*****************************************************************************
  35. *
  36. * FUNCTION : CPCH_Device::EnumerateInstances
  37. *
  38. * DESCRIPTION : Returns all the instances of this class.
  39. *
  40. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  41. * A long that contains the flags described in
  42. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  43. * flags are handled by (and filtered out by) WinMgmt:
  44. * WBEM_FLAG_DEEP
  45. * WBEM_FLAG_SHALLOW
  46. * WBEM_FLAG_RETURN_IMMEDIATELY
  47. * WBEM_FLAG_FORWARD_ONLY
  48. * WBEM_FLAG_BIDIRECTIONAL
  49. *
  50. * RETURNS : WBEM_S_NO_ERROR if successful
  51. *
  52. * COMMENTS : TO DO: All instances on the machine should be returned here.
  53. * If there are no instances, return WBEM_S_NO_ERROR.
  54. * It is not an error to have no instances.
  55. *
  56. *****************************************************************************/
  57. HRESULT CPCH_Device::EnumerateInstances(
  58. MethodContext* pMethodContext,
  59. long lFlags
  60. )
  61. {
  62. TraceFunctEnter("CPCH_Device::EnumerateInstances");
  63. HRESULT hRes = WBEM_S_NO_ERROR;
  64. ULONG ulPNPEntityRetVal;
  65. // Instances
  66. CComPtr<IEnumWbemClassObject> pPNPEntityEnumInst;
  67. // Objects
  68. IWbemClassObjectPtr pPNPEntityObj;
  69. // Query Strings
  70. CComBSTR bstrPNPEntityQuery = L"Select Description, DeviceID FROM Win32_PNPEntity";
  71. // Enumerate the instances of Win32_PNPEntity Class
  72. hRes = ExecWQLQuery(&pPNPEntityEnumInst, bstrPNPEntityQuery);
  73. if (FAILED(hRes))
  74. {
  75. // Cannot get any properties.
  76. goto END;
  77. }
  78. // Query Succeeded
  79. while(WBEM_S_NO_ERROR == pPNPEntityEnumInst->Next(WBEM_INFINITE, 1, &pPNPEntityObj, &ulPNPEntityRetVal))
  80. {
  81. // Create a new instance based on the passed-in MethodContext. If this fails,
  82. // we don't need to check for a null pointer because it throws an exception.
  83. CInstancePtr pPCHDeviceInstance(CreateNewInstance(pMethodContext), false);
  84. CopyProperty(pPNPEntityObj, L"DeviceID", pPCHDeviceInstance, pName);
  85. CopyProperty(pPNPEntityObj, L"Description", pPCHDeviceInstance, pDescription);
  86. hRes = pPCHDeviceInstance->Commit();
  87. if (FAILED(hRes))
  88. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  89. }
  90. END :
  91. TraceFunctLeave();
  92. return hRes ;
  93. }