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.

132 lines
5.6 KiB

  1. //=============================================================================
  2. // This file defines the classes for live WMI data access (which are subclassed
  3. // from the abstract base classes in wmiabstraction.h).
  4. //=============================================================================
  5. #pragma once
  6. #include "wmiabstraction.h"
  7. #include "wbemcli.h"
  8. // Set a timeout value for WMI queries of 20 second. No single WMI operation
  9. // should take longer - if it does, we should assume it isn't coming back.
  10. #define TIMEOUT 20000
  11. //-----------------------------------------------------------------------------
  12. // The CWMILiveObject implements a CWMIObject using a real WMI object. It
  13. // can be created with either a IWbemClassObject pointer, or a services
  14. // pointer and a path.
  15. //-----------------------------------------------------------------------------
  16. class CWMILiveObject : public CWMIObject
  17. {
  18. public:
  19. CWMILiveObject();
  20. virtual ~CWMILiveObject();
  21. // Functions inherited from the base class:
  22. HRESULT GetValue(LPCTSTR szProperty, VARIANT * pvarValue);
  23. HRESULT GetValueString(LPCTSTR szProperty, CString * pstrValue);
  24. HRESULT GetValueDWORD(LPCTSTR szProperty, DWORD * pdwValue);
  25. HRESULT GetValueTime(LPCTSTR szProperty, SYSTEMTIME * psystimeValue);
  26. HRESULT GetValueDoubleFloat(LPCTSTR szProperty, double * pdblValue);
  27. HRESULT GetValueValueMap(LPCTSTR szProperty, CString * pstrValue);
  28. // Functions specific to this subclass:
  29. //
  30. // Note - Create with an object pointer will addref() the pointer:
  31. HRESULT Create(IWbemServices * pServices, IWbemClassObject * pObject);
  32. HRESULT Create(IWbemServices * pServices, LPCTSTR szObjectPath);
  33. private:
  34. IWbemClassObject * m_pObject;
  35. IWbemServices * m_pServices;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // The CWMILiveObjectCollection implements a collection of live WMI objects
  39. // using a WMI enumerator. This collection can be created from an existing
  40. // IEnumWbemClassObject pointer, from a WQL statement or from a WMI class name.
  41. //-----------------------------------------------------------------------------
  42. class CWMILiveObjectCollection : public CWMIObjectCollection
  43. {
  44. public:
  45. CWMILiveObjectCollection(IWbemServices * pServices);
  46. virtual ~CWMILiveObjectCollection();
  47. // Functions inherited from the base class:
  48. HRESULT Create(LPCTSTR szClass, LPCTSTR szProperties = NULL);
  49. HRESULT GetNext(CWMIObject ** ppObject);
  50. // Functions specific to this subclass:
  51. //
  52. // Note - Create with an enum pointer will addref() the pointer:
  53. public:
  54. HRESULT Create(IEnumWbemClassObject * pEnum);
  55. HRESULT CreateWQL(LPCTSTR szQuery);
  56. private:
  57. IEnumWbemClassObject * m_pEnum;
  58. IWbemServices * m_pServices;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // The CWMILiveHelper function encapsulates a WMI connection (which might be to
  62. // XML).
  63. //-----------------------------------------------------------------------------
  64. class CWMILiveHelper : public CWMIHelper
  65. {
  66. public:
  67. CWMILiveHelper();
  68. ~CWMILiveHelper();
  69. HRESULT Enumerate(LPCTSTR szClass, CWMIObjectCollection ** ppCollection, LPCTSTR szProperties = NULL);
  70. HRESULT WQLQuery(LPCTSTR szQuery, CWMIObjectCollection ** ppCollection);
  71. HRESULT NewNamespace(LPCTSTR szNamespace, CWMIHelper **ppNewHelper);
  72. HRESULT GetNamespace(CString * pstrNamespace);
  73. HRESULT GetObject(LPCTSTR szObjectPath, CWMIObject ** ppObject);
  74. public:
  75. // Functions specific to this subclass:
  76. HRESULT Create(LPCTSTR szMachine = NULL, LPCTSTR szNamespace = NULL);
  77. // Check the value map for a given value. This is static since the object
  78. // must be able to call it and there is no back pointer to this class.
  79. static HRESULT CheckValueMap(IWbemServices * pServices, const CString& strClass, const CString& strProperty, const CString& strVal, CString &strResult);
  80. // These functions are specific to version 5.0 refreshes.
  81. BOOL Version5ResetClass(const CString & strClass, GATH_FIELD * pConstraints);
  82. BOOL Version5EnumClass(const CString & strClass, GATH_FIELD * pConstraints);
  83. BOOL Version5QueryValueDWORD(const CString & strClass, const CString & strProperty, DWORD & dwResult, CString & strMessage);
  84. BOOL Version5QueryValueDateTime(const CString & strClass, const CString & strProperty, COleDateTime & datetime, CString & strMessage);
  85. BOOL Version5QueryValueDoubleFloat(const CString & strClass, const CString & strProperty, double & dblResult, CString & strMessage);
  86. BOOL Version5QueryValue(const CString & strClass, const CString & strProperty, CString & strResult);
  87. CMSIEnumerator * Version5GetEnumObject(const CString & strClass, const GATH_FIELD * pConstraints = NULL);
  88. CMSIObject * Version5GetObject(const CString & strClass, const GATH_FIELD * pConstraints, CString * pstrLabel = NULL);
  89. void Version5RemoveObject(const CString & strClass);
  90. IWbemServices * Version5GetWBEMService(CString * pstrNamespace = NULL);
  91. BOOL Version5EvaluateFilter(IWbemClassObject * pObject, const GATH_FIELD * pConstraints);
  92. void Version5EvaluateJoin(const CString & strClass, IWbemClassObject * pObject, const GATH_FIELD * pConstraints);
  93. BOOL Version5IsDependencyJoin(const GATH_FIELD * pConstraints);
  94. void Version5EvaluateDependencyJoin(IWbemClassObject * pObject);
  95. void Version5RemoveEnumObject(const CString & strClass);
  96. void Version5ClearCache();
  97. HRESULT Version5CheckValueMap(const CString& strClass, const CString& strProperty, const CString& strVal, CString &strResult);
  98. private:
  99. HRESULT m_hrError;
  100. CString m_strMachine;
  101. CString m_strNamespace;
  102. IWbemServices * m_pServices;
  103. };