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.

226 lines
8.9 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. CString strOSVersion(_T("Description,Manufacturer,MaxClockSpeed"));
  45. CString strProcessorQuery(_T("Description,Manufacturer"));
  46. CString strProcessorSpeedSource = _T(",MaxClockSpeed");
  47. if (pOSObject != NULL && SUCCEEDED(pOSObject->GetValueString(_T("Version"),&strOSVersion)))
  48. {
  49. if (strOSVersion.Left(3) == _T("5.0"))//remoting to Win2k machine?
  50. {
  51. strProcessorSpeedSource = _T(",CurrentClockSpeed");
  52. }
  53. }
  54. strProcessorQuery += strProcessorSpeedSource;
  55. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_Processor"), &pCollection,strProcessorQuery)))
  56. {
  57. while (S_OK == pCollection->GetNext(&pProcessorObject) && pProcessorObject != NULL)
  58. {
  59. CString strOutput = _T("Description, Manufacturer") + strProcessorSpeedSource;
  60. pWMI->AddObjectToOutput(aColValues, iColCount, pProcessorObject,strOutput /*_T("Description, Manufacturer, MaxClockSpeed")*/, IDS_SYSSUMM3);
  61. delete pProcessorObject;
  62. pProcessorObject = NULL;
  63. }
  64. delete pCollection;
  65. }
  66. // Try to get every property of Win32_BIOS that we'd like to show.
  67. CWMIObject * pBIOSObject = pWMI->GetSingleObject(_T("Win32_BIOS"), _T("Manufacturer, Version, SMBIOSPresent, SMBIOSBIOSVersion, ReleaseDate, SMBIOSMajorVersion, SMBIOSMinorVersion, BIOSVersion"));
  68. // If GetSingleObject failed (the pointer is NULL) try again, without BIOSVersion.
  69. if (pBIOSObject == NULL)
  70. pBIOSObject = pWMI->GetSingleObject(_T("Win32_BIOS"), _T("Manufacturer, Version, SMBIOSPresent, SMBIOSBIOSVersion, ReleaseDate, SMBIOSMajorVersion, SMBIOSMinorVersion"));
  71. if (pBIOSObject)
  72. {
  73. // Per NadirA (bug 409578) this is the preferred order for getting BIOS info.
  74. DWORD dwSMBIOSPresent = 0;
  75. if (FAILED(pBIOSObject->GetValueDWORD(_T("SMBIOSPresent"), &dwSMBIOSPresent)))
  76. dwSMBIOSPresent = 0;
  77. CString strDummy;
  78. if (dwSMBIOSPresent != 0 && SUCCEEDED(pBIOSObject->GetValueString(_T("SMBIOSBIOSVersion"), &strDummy)))
  79. {
  80. // We need to change the format strings for the BIOS and SMBIOS values in this case.
  81. CString strBIOSFormat, strSMBIOSFormat;
  82. strBIOSFormat.LoadString(IDS_SYSSUMM4);
  83. strSMBIOSFormat.LoadString(IDS_SYSSUMM11);
  84. strBIOSFormat = strBIOSFormat.SpanExcluding(_T("|")) + CString(_T("|%s %s, %c"));
  85. strSMBIOSFormat = strSMBIOSFormat.SpanExcluding(_T("|")) + CString(_T("|%d.%d"));
  86. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("Manufacturer, SMBIOSBIOSVersion, ReleaseDate"), strBIOSFormat);
  87. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("SMBIOSMajorVersion, SMBIOSMinorVersion"), strSMBIOSFormat);
  88. }
  89. else if (SUCCEEDED(pBIOSObject->GetValueString(_T("BIOSVersion"), &strDummy)))
  90. {
  91. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("BIOSVersion, ReleaseDate"), IDS_SYSSUMM4);
  92. }
  93. else
  94. {
  95. pWMI->AddObjectToOutput(aColValues, iColCount, pBIOSObject, _T("Version, ReleaseDate"), IDS_SYSSUMM4);
  96. }
  97. }
  98. if (pOSObject)
  99. pWMI->AddObjectToOutput(aColValues, iColCount, pOSObject, _T("WindowsDirectory, MSIAdvancedSystemDirectory, MSIAdvancedBootDevice, Locale"), IDS_SYSSUMM5);
  100. // Add information about the HAL.DLL to the summary (bug 382771). The DLL
  101. // will be found in the system directory.
  102. if (pOSObject != NULL)
  103. {
  104. CString strSystemDirectory = pOSObject->GetString(_T("SystemDirectory"));
  105. if (!strSystemDirectory.IsEmpty())
  106. {
  107. CString strPath;
  108. strPath.Format(_T("CIM_DataFile.Name='%s\\hal.dll'"), strSystemDirectory);
  109. CWMIObject * pHALObject;
  110. if (SUCCEEDED(pWMI->GetObject(strPath, &pHALObject)))
  111. {
  112. pWMI->AddObjectToOutput(aColValues, iColCount, pHALObject, _T("Version"), IDS_SYSSUMM13);
  113. delete pHALObject;
  114. }
  115. }
  116. }
  117. if (pComputerObject)
  118. pWMI->AddObjectToOutput(aColValues, iColCount, pComputerObject, _T("MSIAdvancedUserName"), IDS_SYSSUMM6);
  119. if (pComputerObject)
  120. {
  121. BOOL fUseStandard = TRUE;
  122. DWORD dwValue;
  123. if (SUCCEEDED(pComputerObject->GetValueDWORD(_T("DaylightInEffect"), &dwValue)) && dwValue)
  124. fUseStandard = FALSE;
  125. CWMIObject * pTimeZoneObject = pWMI->GetSingleObject(_T("Win32_TimeZone"));
  126. if (pTimeZoneObject)
  127. {
  128. pWMI->AddObjectToOutput(aColValues, iColCount, pTimeZoneObject, (fUseStandard) ? _T("StandardName") : _T("DaylightName"), IDS_SYSSUMM10);
  129. delete pTimeZoneObject;
  130. }
  131. }
  132. // To get an accurate picture of the we need to enumerate the values of Win32_PhysicalMemory,
  133. // which reports the memory installed in each slot.
  134. double dblTotalPhysicalMemory = 0.0;
  135. pCollection = NULL;
  136. CWMIObject * pMemoryObject = NULL;
  137. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_PhysicalMemory"), &pCollection, _T("Capacity"))))
  138. {
  139. while (S_OK == pCollection->GetNext(&pMemoryObject) && pMemoryObject != NULL)
  140. {
  141. double dblTemp;
  142. if (SUCCEEDED(pMemoryObject->GetValueDoubleFloat(_T("Capacity"), &dblTemp)))
  143. dblTotalPhysicalMemory += dblTemp;
  144. delete pMemoryObject;
  145. pMemoryObject = NULL;
  146. }
  147. delete pCollection;
  148. }
  149. // On some older machines, without SMBIOS, Win32_PhysicalMemory isn't supported.
  150. // In that case, look at Win32_ComputerSystem::TotalPhysicalMemory. XP bug 441343.
  151. if (dblTotalPhysicalMemory == 0.0)
  152. {
  153. CWMIObject * pObject = pWMI->GetSingleObject(_T("Win32_ComputerSystem"), _T("TotalPhysicalMemory"));
  154. if (pObject != NULL)
  155. if (FAILED(pObject->GetValueDoubleFloat(_T("TotalPhysicalMemory"), &dblTotalPhysicalMemory)))
  156. dblTotalPhysicalMemory = 0.0;
  157. }
  158. if (dblTotalPhysicalMemory != 0.0)
  159. {
  160. CString strCaption;
  161. CString strValue(DelimitNumber(dblTotalPhysicalMemory/(1024.0*1024.0), 2));
  162. if (gstrMB.IsEmpty())
  163. gstrMB.LoadString(IDS_MB);
  164. strValue += _T(" ") + gstrMB;
  165. // For the caption, use the format string we used before (just the first column).
  166. strCaption.LoadString(IDS_SYSSUMM7);
  167. strCaption = strCaption.SpanExcluding(_T("|"));
  168. pWMI->AppendCell(aColValues[0], strCaption, 0);
  169. pWMI->AppendCell(aColValues[1], strValue, (DWORD)dblTotalPhysicalMemory);
  170. }
  171. if (pOSObject)
  172. pWMI->AddObjectToOutput(aColValues, iColCount, pOSObject, _T("FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory, SizeStoredInPagingFiles"), IDS_SYSSUMM8);
  173. if (pPFUObject)
  174. pWMI->AddObjectToOutput(aColValues, iColCount, pPFUObject, _T("MSIAdvancedCaption"), IDS_SYSSUMM9);
  175. if (pOSObject) delete pOSObject;
  176. if (pComputerObject) delete pComputerObject;
  177. if (pProcessorObject) delete pProcessorObject;
  178. if (pBIOSObject) delete pBIOSObject ;
  179. if (pPFUObject) delete pPFUObject;
  180. return S_OK;
  181. }