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.

241 lines
8.8 KiB

  1. //=============================================================================
  2. // Contains the refresh functions for the software environment categories.
  3. //=============================================================================
  4. #include "stdafx.h"
  5. #include "category.h"
  6. #include "dataset.h"
  7. #include "wmiabstraction.h"
  8. //-----------------------------------------------------------------------------
  9. // This function gathers running task information.
  10. //-----------------------------------------------------------------------------
  11. HRESULT RunningTasks(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  12. {
  13. ASSERT(pWMI == NULL || aColValues);
  14. if (pWMI == NULL)
  15. return S_OK;
  16. LPCTSTR szTaskProperties = _T("Name, ExecutablePath, ProcessID, Priority, MinimumWorkingSetSize, MaximumWorkingSetSize, CreationDate");
  17. CString strName, strPath, strProcessID, strPriority, strMinWorking, strMaxWorking, strStartTime;
  18. CString strFileObjectPath, strDate, strSize, strVersion;
  19. DWORD dwProcessID, dwPriority, dwMinWorking, dwMaxWorking, dwStartTime, dwDate, dwSize;
  20. HRESULT hr = S_OK;
  21. CWMIObjectCollection * pCollection = NULL;
  22. hr = pWMI->Enumerate(_T("Win32_Process"), &pCollection, szTaskProperties);
  23. if (SUCCEEDED(hr))
  24. {
  25. CWMIObject * pObject = NULL;
  26. CWMIObject * pFileObject = NULL;
  27. while (S_OK == pCollection->GetNext(&pObject))
  28. {
  29. strName.Empty(); strPath.Empty(); strProcessID.Empty(); strPriority.Empty();
  30. strMinWorking.Empty(); strMaxWorking.Empty(); strStartTime.Empty();
  31. strDate.Empty(); strSize.Empty(); strVersion.Empty();
  32. dwProcessID = dwPriority = dwMinWorking = dwMaxWorking = dwStartTime = dwDate = dwSize = 0;
  33. pObject->GetInterpretedValue(_T("Name"), _T("%l"), _T('l'), &strName, NULL);
  34. pObject->GetInterpretedValue(_T("ExecutablePath"), _T("%l"), _T('l'), &strPath, NULL);
  35. //pObject->GetInterpretedValue(_T("ProcessID"), _T("0x%08x"), _T('x'), &strProcessID, &dwProcessID);
  36. //a-kjaw . to fix bug "MSInfo: Running Tasks PID's are being displayed in HEX"
  37. pObject->GetInterpretedValue(_T("ProcessID"), _T("%d"), _T('x'), &strProcessID, &dwProcessID);
  38. //a-kjaw
  39. pObject->GetInterpretedValue(_T("Priority"), _T("%d"), _T('d'), &strPriority, &dwPriority);
  40. pObject->GetInterpretedValue(_T("MinimumWorkingSetSize"), _T("%d"), _T('d'), &strMinWorking, &dwMinWorking);
  41. pObject->GetInterpretedValue(_T("MaximumWorkingSetSize"), _T("%d"), _T('d'), &strMaxWorking, &dwMaxWorking);
  42. pObject->GetInterpretedValue(_T("CreationDate"), _T("%t"), _T('t'), &strStartTime, &dwStartTime);
  43. strFileObjectPath.Format(_T("CIM_DataFile.Name='%s'"), strPath);
  44. if (SUCCEEDED(pWMI->GetObject(strFileObjectPath, &pFileObject)))
  45. {
  46. pFileObject->GetInterpretedValue(_T("CreationDate"), _T("%t"), _T('t'), &strDate, &dwDate);
  47. pFileObject->GetInterpretedValue(_T("FileSize"), _T("%z"), _T('z'), &strSize, &dwSize);
  48. pFileObject->GetInterpretedValue(_T("Version"), _T("%s"), _T('s'), &strVersion, NULL);
  49. delete pFileObject;
  50. pFileObject = NULL;
  51. }
  52. else
  53. {
  54. strVersion = strSize = strDate = GetMSInfoHRESULTString(E_MSINFO_NOVALUE);
  55. }
  56. pWMI->AppendCell(aColValues[0], strName, 0);
  57. pWMI->AppendCell(aColValues[1], strPath, 0);
  58. pWMI->AppendCell(aColValues[2], strProcessID, dwProcessID);
  59. pWMI->AppendCell(aColValues[3], strPriority, dwPriority);
  60. pWMI->AppendCell(aColValues[4], strMinWorking, dwMinWorking);
  61. pWMI->AppendCell(aColValues[5], strMaxWorking, dwMaxWorking);
  62. pWMI->AppendCell(aColValues[6], strStartTime, dwStartTime);
  63. pWMI->AppendCell(aColValues[7], strVersion, 0);
  64. pWMI->AppendCell(aColValues[8], strSize, dwSize);
  65. pWMI->AppendCell(aColValues[9], strDate, dwDate);
  66. }
  67. delete pObject;
  68. delete pCollection;
  69. }
  70. return hr;
  71. }
  72. //-----------------------------------------------------------------------------
  73. // This function gathers loaded module information.
  74. //
  75. // The list of loaded modules contains all the executables and other entities
  76. // (such as DLLs) which are currently loaded. This can be found using the
  77. // WMI class CIM_ProcessExecutable. The trick is to remove duplicates (since
  78. // DLLs will show up for each time they are loaded).
  79. //-----------------------------------------------------------------------------
  80. HRESULT LoadedModules(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  81. {
  82. ASSERT(pWMI == NULL || aColValues);
  83. ASSERT(iColCount == 6);
  84. if (pWMI == NULL)
  85. return S_OK;
  86. HRESULT hr = S_OK;
  87. CString strAntecedent;
  88. CStringList listModules;
  89. // Enumerate the CIM_ProcessExecutable class, creating a list of unique
  90. // loaded files.
  91. CWMIObjectCollection * pCollection = NULL;
  92. hr = pWMI->Enumerate(_T("CIM_ProcessExecutable"), &pCollection);
  93. if (SUCCEEDED(hr))
  94. {
  95. CWMIObject * pObject = NULL;
  96. while (S_OK == pCollection->GetNext(&pObject))
  97. {
  98. if (SUCCEEDED(pObject->GetValueString(_T("Antecedent"), &strAntecedent)))
  99. {
  100. strAntecedent.MakeLower();
  101. if (NULL == listModules.Find(strAntecedent))
  102. listModules.AddTail(strAntecedent);
  103. }
  104. }
  105. delete pObject;
  106. delete pCollection;
  107. }
  108. // Traverse the list of unique modules and get information for each file.
  109. CWMIObject * pFileObject;
  110. CString strFileObject;
  111. while (!listModules.IsEmpty())
  112. {
  113. strFileObject = listModules.RemoveHead();
  114. int iColon = strFileObject.Find(_T(":"));
  115. if (iColon != -1)
  116. strFileObject = strFileObject.Right(strFileObject.GetLength() - iColon - 1);
  117. if (SUCCEEDED(pWMI->GetObject(strFileObject, &pFileObject)))
  118. {
  119. pWMI->AddObjectToOutput(aColValues, iColCount, pFileObject, _T("FileName, Version, FileSize, CreationDate, Manufacturer, Name"), IDS_LOADEDMODULE1);
  120. delete pFileObject;
  121. }
  122. else
  123. {
  124. int iEquals = strFileObject.Find(_T("="));
  125. if (iEquals != -1)
  126. strFileObject = strFileObject.Right(strFileObject.GetLength() - iEquals - 1);
  127. // TBD - old MFC doesn't have these: strFileObject.TrimLeft(_T("\"'"));
  128. // strFileObject.TrimRight(_T("\"'"));
  129. StringReplace(strFileObject, _T("\\\\"), _T("\\"));
  130. pWMI->AppendCell(aColValues[0], strFileObject, 0);
  131. pWMI->AppendCell(aColValues[1], _T(""), 0);
  132. pWMI->AppendCell(aColValues[2], _T(""), 0);
  133. pWMI->AppendCell(aColValues[3], _T(""), 0);
  134. pWMI->AppendCell(aColValues[4], _T(""), 0);
  135. pWMI->AppendCell(aColValues[5], strFileObject, 0);
  136. }
  137. }
  138. return hr;
  139. }
  140. //-----------------------------------------------------------------------------
  141. // This function gathers OLE information.
  142. //-----------------------------------------------------------------------------
  143. HRESULT OLERegistration(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  144. {
  145. ASSERT(pWMI == NULL || aColValues);
  146. ASSERT(iColCount == 2);
  147. if (pWMI == NULL)
  148. return S_OK;
  149. HRESULT hr = S_OK;
  150. CString strCheckObject;
  151. int i = 1;
  152. CWMIObjectCollection * pCollection = NULL;
  153. hr = pWMI->Enumerate(_T("Win32_ClassicCOMClassSetting"), &pCollection, _T("Caption, LocalServer32, Insertable, Control"));
  154. if (SUCCEEDED(hr))
  155. {
  156. CWMIObject * pObject = NULL;
  157. while (S_OK == pCollection->GetNext(&pObject))
  158. {
  159. DWORD dwInsertable = 0, dwControl = -1;
  160. pObject->GetValueDWORD(_T("Insertable"), &dwInsertable);
  161. pObject->GetValueDWORD(_T("Control"), &dwControl);
  162. if (dwInsertable == -1 && dwControl == 0)
  163. {
  164. if (SUCCEEDED(pObject->GetValueString(_T("Caption"), &strCheckObject)) && !strCheckObject.IsEmpty())
  165. pWMI->AddObjectToOutput(aColValues, iColCount, pObject, _T("Caption, LocalServer32"), IDS_OLEREG1);
  166. }
  167. }
  168. delete pObject;
  169. delete pCollection;
  170. }
  171. return hr;
  172. }
  173. HRESULT WindowsErrorReporting(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  174. {
  175. ASSERT(pWMI == NULL || aColValues);
  176. if (pWMI == NULL)
  177. return S_OK;
  178. HRESULT hr = S_OK;
  179. LPCTSTR aszQueries[] =
  180. {
  181. _T("SELECT TimeGenerated, SourceName, Message FROM Win32_NTLogEvent WHERE EventIdentifier = 1000"),
  182. _T("SELECT TimeGenerated, SourceName, Message FROM Win32_NTLogEvent WHERE EventIdentifier = 1001"),
  183. _T("SELECT TimeGenerated, SourceName, Message FROM Win32_NTLogEvent WHERE EventIdentifier = 1002"),
  184. NULL
  185. };
  186. for (int i = 0; aszQueries[i] != NULL; i++)
  187. {
  188. CWMIObjectCollection * pCollection = NULL;
  189. if (SUCCEEDED(pWMI->WQLQuery(aszQueries[i], &pCollection)))
  190. {
  191. CWMIObject * pObject = NULL;
  192. while (S_OK == pCollection->GetNext(&pObject))
  193. {
  194. pWMI->AddObjectToOutput(aColValues, iColCount, pObject, _T("TimeGenerated, SourceName, Message"), IDS_SWWINERR1);
  195. }
  196. delete pObject;
  197. delete pCollection;
  198. }
  199. }
  200. return hr;
  201. }