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.

142 lines
2.9 KiB

  1. // HMSystem.cpp: implementation of the CHMSystemConfiguration class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMSystem.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMSystemConfiguration,CWbemClassObject)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMSystemConfiguration::CHMSystemConfiguration()
  17. {
  18. m_bEnable = 1;
  19. }
  20. CHMSystemConfiguration::~CHMSystemConfiguration()
  21. {
  22. Destroy();
  23. }
  24. //////////////////////////////////////////////////////////////////////
  25. // Create
  26. //////////////////////////////////////////////////////////////////////
  27. HRESULT CHMSystemConfiguration::Create(const CString& sMachineName)
  28. {
  29. HRESULT hr = CWbemClassObject::Create(sMachineName);
  30. if( !CHECKHRESULT(hr) )
  31. {
  32. return hr;
  33. }
  34. // create the enumerator for Microsoft_HMSystemConfiguration object instances
  35. BSTR bsClass = SysAllocString(_T("Microsoft_HMSystemConfiguration"));
  36. hr = CreateEnumerator(bsClass);
  37. SysFreeString(bsClass);
  38. if( !CHECKHRESULT(hr) )
  39. {
  40. return hr;
  41. }
  42. return hr;
  43. }
  44. HRESULT CHMSystemConfiguration::Create(IWbemClassObject* pObject)
  45. {
  46. HRESULT hr = CWbemClassObject::Create(pObject);
  47. if( !CHECKHRESULT(hr) )
  48. {
  49. return hr;
  50. }
  51. return hr;
  52. }
  53. //////////////////////////////////////////////////////////////////////
  54. // Enumeration Operations
  55. //////////////////////////////////////////////////////////////////////
  56. HRESULT CHMSystemConfiguration::EnumerateObjects(ULONG& uReturned)
  57. {
  58. // call GetNextObject to proceed to the next object instance
  59. HRESULT hr = GetNextObject(uReturned);
  60. if( FAILED(hr) || uReturned != 1 )
  61. {
  62. // no more instances
  63. return hr;
  64. }
  65. ASSERT(m_pIWbemClassObject);
  66. if( m_pIWbemClassObject == NULL )
  67. {
  68. ASSERT(0);
  69. return S_FALSE;
  70. }
  71. // process the properties of this object
  72. hr = GetAllProperties();
  73. return hr;
  74. }
  75. //////////////////////////////////////////////////////////////////////
  76. // Property Retrieval Operations
  77. //////////////////////////////////////////////////////////////////////
  78. HRESULT CHMSystemConfiguration::GetAllProperties()
  79. {
  80. ASSERT(m_pIWbemClassObject);
  81. if( m_pIWbemClassObject == NULL )
  82. {
  83. ASSERT(FALSE);
  84. return S_FALSE;
  85. }
  86. HRESULT hr = S_OK;
  87. // Enable
  88. hr = GetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  89. // GUID
  90. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGuid);
  91. m_sGuid.TrimLeft(_T("{"));
  92. m_sGuid.TrimRight(_T("}"));
  93. return hr;
  94. }
  95. HRESULT CHMSystemConfiguration::SaveEnabledProperty()
  96. {
  97. ASSERT(m_pIWbemClassObject);
  98. if( m_pIWbemClassObject == NULL )
  99. {
  100. ASSERT(FALSE);
  101. return S_FALSE;
  102. }
  103. HRESULT hr = S_OK;
  104. // Enable
  105. hr = SetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  106. ASSERT(SUCCEEDED(hr));
  107. hr = SaveAllProperties();
  108. ASSERT(SUCCEEDED(hr));
  109. return hr;
  110. }