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.

214 lines
8.1 KiB

  1. //=============================================================================
  2. // Contains the refresh function for the system summary category.
  3. //=============================================================================
  4. #include "stdafx.h"
  5. #include "category.h"
  6. #include "dataset.h"
  7. #include "wmiabstraction.h"
  8. extern CString DelimitNumber(double dblValue, int iDecimalDigits = 0);
  9. extern CString gstrMB; // global string "MB" (will be localized)
  10. HRESULT SystemSummary(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  11. {
  12. ASSERT(pWMI == NULL || (aColValues && iColCount == 2));
  13. // Get the WMI objects we'll be needing. We'll check the first one to see if we
  14. // have a connection to WMI.
  15. CWMIObjectCollection * pCollection = NULL;
  16. CWMIObject * pOSObject = NULL;
  17. HRESULT hr = pWMI->Enumerate(_T("Win32_OperatingSystem"), &pCollection); //, _T("Caption, Version, CSDVersion, BuildNumber, Manufacturer, WindowsDirectory, SystemDirectory, BootDevice, Locale, FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory, SizeStoredInPagingFiles"));
  18. if (SUCCEEDED(hr))
  19. {
  20. hr = pCollection->GetNext(&pOSObject);
  21. if (FAILED(hr))
  22. pOSObject = NULL;
  23. delete pCollection;
  24. }
  25. if (FAILED(hr))
  26. return hr;
  27. CWMIObject * pComputerObject = pWMI->GetSingleObject(_T("Win32_ComputerSystem"), _T("Name, Manufacturer, Model, SystemType, UserName, DaylightInEffect"));
  28. CWMIObject * pPFUObject = pWMI->GetSingleObject(_T("Win32_PageFileUsage"), _T("Caption"));
  29. if (pOSObject)
  30. pWMI->AddObjectToOutput(aColValues, iColCount, pOSObject, _T("Caption, Version, CSDVersion, BuildNumber, Manufacturer"), IDS_SYSSUMM1);
  31. // If the system has activation pending, show the number of days left.
  32. CWMIObject * pActivationObject = pWMI->GetSingleObject(_T("Win32_WindowsProductActivation"), _T("RemainingGracePeriod, ActivationRequired"));
  33. if (pActivationObject != NULL)
  34. {
  35. DWORD dwActivationPending;
  36. if (SUCCEEDED(pActivationObject->GetValueDWORD(_T("ActivationRequired"), &dwActivationPending)) && dwActivationPending != 0)
  37. pWMI->AddObjectToOutput(aColValues, iColCount, pActivationObject, _T("RemainingGracePeriod"), IDS_SYSSUMM12);
  38. delete pActivationObject;
  39. }
  40. if (pComputerObject)
  41. pWMI->AddObjectToOutput(aColValues, iColCount, pComputerObject, _T("Name, Manufacturer, Model, SystemType"), IDS_SYSSUMM2);
  42. pCollection = NULL;
  43. CWMIObject * pProcessorObject = NULL;
  44. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_Processor"), &pCollection, _T("Description, Manufacturer, MaxClockSpeed"))))
  45. {
  46. while (S_OK == pCollection->GetNext(&pProcessorObject) && pProcessorObject != NULL)
  47. {
  48. pWMI->AddObjectToOutput(aColValues, iColCount, pProcessorObject, _T("Description, Manufacturer, MaxClockSpeed"), IDS_SYSSUMM3);
  49. delete pProcessorObject;
  50. pProcessorObject = NULL;
  51. }
  52. delete pCollection;
  53. }
  54. // Try to get every property of Win32_BIOS that we'd like to show.
  55. CWMIObject * pBIOSObject = pWMI->GetSingleObject(_T("Win32_BIOS"), _T("Manufacturer, Version, SMBIOSPresent, SMBIOSBIOSVersion, ReleaseDate, SMBIOSMajorVersion, SMBIOSMinorVersion, BIOSVersion"));
  56. // If GetSingleObject failed (the pointer is NULL) try again, without BIOSVersion.
  57. if (pBIOSObject == NULL)
  58. pBIOSObject = pWMI->GetSingleObject(_T("Win32_BIOS"), _T("Manufacturer, Version, SMBIOSPresent, SMBIOSBIOSVersion, ReleaseDate, SMBIOSMajorVersion, SMBIOSMinorVersion"));
  59. if (pBIOSObject)
  60. {
  61. // Per NadirA (bug 409578) this is the preferred order for getting BIOS info.
  62. DWORD dwSMBIOSPresent = 0;
  63. if (FAILED(pBIOSObject->GetValueDWORD(_T("SMBIOSPresent"), &dwSMBIOSPresent)))
  64. dwSMBIOSPresent = 0;
  65. CString strDummy;
  66. if (dwSMBIOSPresent != 0 && SUCCEEDED(pBIOSObject->GetValueString(_T("SMBIOSBIOSVersion"), &strDummy)))
  67. {
  68. // We need to change the format strings for the BIOS and SMBIOS values in this case.
  69. CString strBIOSFormat, strSMBIOSFormat;
  70. strBIOSFormat.LoadString(IDS_SYSSUMM4);
  71. strSMBIOSFormat.LoadString(IDS_SYSSUMM11);
  72. strBIOSFormat = strBIOSFormat.SpanExcluding(_T("|")) + CString(_T("|%s %s, %c"));
  73. strSMBIOSFormat = strSMBIOSFormat.SpanExcluding(_T("|")) + CString(_T("|%d.%d"));
  74. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("Manufacturer, SMBIOSBIOSVersion, ReleaseDate"), strBIOSFormat);
  75. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("SMBIOSMajorVersion, SMBIOSMinorVersion"), strSMBIOSFormat);
  76. }
  77. else if (SUCCEEDED(pBIOSObject->GetValueString(_T("BIOSVersion"), &strDummy)))
  78. {
  79. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("BIOSVersion, ReleaseDate"), IDS_SYSSUMM4);
  80. }
  81. else
  82. {
  83. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("Version, ReleaseDate"), IDS_SYSSUMM4);
  84. }
  85. }
  86. if (pOSObject)
  87. pWMI->AddObjectToOutput(aColValues, iColCount, pOSObject, _T("WindowsDirectory, MSIAdvancedSystemDirectory, MSIAdvancedBootDevice, Locale"), IDS_SYSSUMM5);
  88. // Add information about the HAL.DLL to the summary (bug 382771). The DLL
  89. // will be found in the system directory.
  90. if (pOSObject != NULL)
  91. {
  92. CString strSystemDirectory = pOSObject->GetString(_T("SystemDirectory"));
  93. if (!strSystemDirectory.IsEmpty())
  94. {
  95. CString strPath;
  96. strPath.Format(_T("CIM_DataFile.Name='%s\\hal.dll'"), strSystemDirectory);
  97. CWMIObject * pHALObject;
  98. if (SUCCEEDED(pWMI->GetObject(strPath, &pHALObject)))
  99. {
  100. pWMI->AddObjectToOutput(aColValues, iColCount, pHALObject, _T("Version"), IDS_SYSSUMM13);
  101. delete pHALObject;
  102. }
  103. }
  104. }
  105. if (pComputerObject)
  106. pWMI->AddObjectToOutput(aColValues, iColCount, pComputerObject, _T("MSIAdvancedUserName"), IDS_SYSSUMM6);
  107. if (pComputerObject)
  108. {
  109. BOOL fUseStandard = TRUE;
  110. DWORD dwValue;
  111. if (SUCCEEDED(pComputerObject->GetValueDWORD(_T("DaylightInEffect"), &dwValue)) && dwValue)
  112. fUseStandard = FALSE;
  113. CWMIObject * pTimeZoneObject = pWMI->GetSingleObject(_T("Win32_TimeZone"));
  114. if (pTimeZoneObject)
  115. {
  116. pWMI->AddObjectToOutput(aColValues, iColCount, pTimeZoneObject, (fUseStandard) ? _T("StandardName") : _T("DaylightName"), IDS_SYSSUMM10);
  117. delete pTimeZoneObject;
  118. }
  119. }
  120. // To get an accurate picture of the we need to enumerate the values of Win32_PhysicalMemory,
  121. // which reports the memory installed in each slot.
  122. double dblTotalPhysicalMemory = 0.0;
  123. pCollection = NULL;
  124. CWMIObject * pMemoryObject = NULL;
  125. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_PhysicalMemory"), &pCollection, _T("Capacity"))))
  126. {
  127. while (S_OK == pCollection->GetNext(&pMemoryObject) && pMemoryObject != NULL)
  128. {
  129. double dblTemp;
  130. if (SUCCEEDED(pMemoryObject->GetValueDoubleFloat(_T("Capacity"), &dblTemp)))
  131. dblTotalPhysicalMemory += dblTemp;
  132. delete pMemoryObject;
  133. pMemoryObject = NULL;
  134. }
  135. delete pCollection;
  136. }
  137. // On some older machines, without SMBIOS, Win32_PhysicalMemory isn't supported.
  138. // In that case, look at Win32_ComputerSystem::TotalPhysicalMemory. XP bug 441343.
  139. if (dblTotalPhysicalMemory == 0.0)
  140. {
  141. CWMIObject * pObject = pWMI->GetSingleObject(_T("Win32_ComputerSystem"), _T("TotalPhysicalMemory"));
  142. if (pObject != NULL)
  143. if (FAILED(pObject->GetValueDoubleFloat(_T("TotalPhysicalMemory"), &dblTotalPhysicalMemory)))
  144. dblTotalPhysicalMemory = 0.0;
  145. }
  146. if (dblTotalPhysicalMemory != 0.0)
  147. {
  148. CString strCaption;
  149. CString strValue(DelimitNumber(dblTotalPhysicalMemory/(1024.0*1024.0), 2));
  150. if (gstrMB.IsEmpty())
  151. gstrMB.LoadString(IDS_MB);
  152. strValue += _T(" ") + gstrMB;
  153. // For the caption, use the format string we used before (just the first column).
  154. strCaption.LoadString(IDS_SYSSUMM7);
  155. strCaption = strCaption.SpanExcluding(_T("|"));
  156. pWMI->AppendCell(aColValues[0], strCaption, 0);
  157. pWMI->AppendCell(aColValues[1], strValue, (DWORD)dblTotalPhysicalMemory);
  158. }
  159. if (pOSObject)
  160. pWMI->AddObjectToOutput(aColValues, iColCount, pOSObject, _T("FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory, SizeStoredInPagingFiles"), IDS_SYSSUMM8);
  161. if (pPFUObject)
  162. pWMI->AddObjectToOutput(aColValues, iColCount, pPFUObject, _T("MSIAdvancedCaption"), IDS_SYSSUMM9);
  163. if (pOSObject) delete pOSObject;
  164. if (pComputerObject) delete pComputerObject;
  165. if (pProcessorObject) delete pProcessorObject;
  166. if (pBIOSObject) delete pBIOSObject ;
  167. if (pPFUObject) delete pPFUObject;
  168. return S_OK;
  169. }