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.

317 lines
11 KiB

  1. //=============================================================================
  2. // Contains the refresh functions for the resource categories.
  3. //=============================================================================
  4. #include "stdafx.h"
  5. #include "category.h"
  6. #include "dataset.h"
  7. #include "wmiabstraction.h"
  8. //-----------------------------------------------------------------------------
  9. // This function gathers CODEC (audio and video) information.
  10. //-----------------------------------------------------------------------------
  11. HRESULT CODECs(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. HRESULT hr = S_OK;
  17. CWMIObjectCollection * pCollection = NULL;
  18. CString strGroup = (dwIndex == CODEC_AUDIO) ? _T("Audio") : _T("Video");
  19. LPCTSTR szProperties = _T("EightDotThreeFileName, Manufacturer, Description, Status, Name, Version, FileSize, CreationDate, Group");
  20. hr = pWMI->Enumerate(_T("Win32_CODECFile"), &pCollection, szProperties);
  21. if (SUCCEEDED(hr))
  22. {
  23. CWMIObject * pObject = NULL;
  24. while (S_OK == pCollection->GetNext(&pObject))
  25. if (strGroup.CompareNoCase(pObject->GetString(_T("Group"))) == 0)
  26. pWMI->AddObjectToOutput(aColValues, iColCount, pObject, szProperties, IDS_CODEC1);
  27. delete pObject;
  28. delete pCollection;
  29. }
  30. return hr;
  31. }
  32. //-----------------------------------------------------------------------------
  33. // This function gathers Drive information.
  34. //-----------------------------------------------------------------------------
  35. HRESULT ComponentDrives(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  36. {
  37. ASSERT(pWMI == NULL || aColValues);
  38. if (pWMI == NULL)
  39. return S_OK;
  40. HRESULT hr = S_OK;
  41. // Get all of the logical drives. There should be at most 26 of them, since they're limited
  42. // by drive letter assignments.
  43. CWMIObject * apDriveObjects[26];
  44. ::ZeroMemory(apDriveObjects, sizeof(CWMIObject *) * 26);
  45. CWMIObjectCollection * pCollection = NULL;
  46. hr = pWMI->Enumerate(_T("Win32_LogicalDisk"), &pCollection, _T("DriveType, DeviceID, Description, Compressed, FileSystem, Size, FreeSpace, VolumeName, VolumeSerialNumber, PNPDeviceID, ProviderName"));
  47. if (SUCCEEDED(hr))
  48. {
  49. CWMIObject * pObject = NULL;
  50. while (S_OK == pCollection->GetNext(&pObject))
  51. {
  52. CString strDeviceID = pObject->GetString(_T("DeviceID"));
  53. if (!strDeviceID.IsEmpty())
  54. {
  55. strDeviceID.MakeUpper();
  56. TCHAR chDriveLetter = strDeviceID[0];
  57. if (chDriveLetter >= _T('A') && chDriveLetter <= _T('Z'))
  58. apDriveObjects[chDriveLetter - _T('A')] = pObject;
  59. else
  60. delete pObject;
  61. }
  62. else
  63. delete pObject;
  64. pObject = NULL;
  65. }
  66. delete pCollection;
  67. }
  68. for (int index = 0; index < 26; index++)
  69. if (apDriveObjects[index])
  70. {
  71. DWORD dwType;
  72. if (SUCCEEDED(apDriveObjects[index]->GetValueDWORD(_T("DriveType"), &dwType)))
  73. {
  74. // Depending on the type of the drive, display different information.
  75. switch (dwType)
  76. {
  77. case 2:
  78. pWMI->AppendBlankLine(aColValues, iColCount);
  79. pWMI->AddObjectToOutput(aColValues, iColCount, apDriveObjects[index], _T("DeviceID, Description"), IDS_DRIVESTYPE2);
  80. break;
  81. case 3:
  82. pWMI->AppendBlankLine(aColValues, iColCount);
  83. pWMI->AddObjectToOutput(aColValues, iColCount, apDriveObjects[index], _T("DeviceID, Description, Compressed, MSIAdvancedFileSystem, Size, FreeSpace, MSIAdvancedVolumeName, MSIAdvancedVolumeSerialNumber, MSIAdvancedPNPDeviceID"), IDS_DRIVESTYPE3);
  84. break;
  85. case 4:
  86. pWMI->AppendBlankLine(aColValues, iColCount);
  87. pWMI->AddObjectToOutput(aColValues, iColCount, apDriveObjects[index], _T("DeviceID, Description, ProviderName"), IDS_DRIVESTYPE4);
  88. break;
  89. case 5:
  90. pWMI->AppendBlankLine(aColValues, iColCount);
  91. pWMI->AddObjectToOutput(aColValues, iColCount, apDriveObjects[index], _T("DeviceID, Description"), IDS_DRIVESTYPE2);
  92. break;
  93. }
  94. }
  95. delete apDriveObjects[index];
  96. }
  97. return hr;
  98. }
  99. //-----------------------------------------------------------------------------
  100. // This function gathers WinSock information.
  101. //-----------------------------------------------------------------------------
  102. HRESULT Winsock(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  103. {
  104. ASSERT(pWMI == NULL || aColValues);
  105. if (pWMI == NULL)
  106. return S_OK;
  107. // Get the system directory.
  108. CWMIObjectCollection * pCollection = NULL;
  109. CWMIObject * pOSObject = NULL;
  110. HRESULT hr = pWMI->Enumerate(_T("Win32_OperatingSystem"), &pCollection);
  111. if (SUCCEEDED(hr))
  112. {
  113. hr = pCollection->GetNext(&pOSObject);
  114. if (FAILED(hr))
  115. pOSObject = NULL;
  116. delete pCollection;
  117. }
  118. if (pOSObject == NULL)
  119. return hr;
  120. CString strSystemDirectory = pOSObject->GetString(_T("SystemDirectory"));
  121. delete pOSObject;
  122. if (strSystemDirectory.IsEmpty())
  123. return S_OK;
  124. // This is the set of WINSOCK files we'll be looking at.
  125. CString astrFiles[] = { _T("winsock.dll"), _T("wsock32.dll"), _T("wsock32n.dll"), _T("") };
  126. for (int index = 0; !astrFiles[index].IsEmpty(); index++)
  127. {
  128. // Get the object for the CIM_DataFile for this specific file.
  129. CString strPath;
  130. strPath.Format(_T("CIM_DataFile.Name='%s\\%s'"), strSystemDirectory, astrFiles[index]);
  131. CWMIObject * pObject;
  132. if (SUCCEEDED(pWMI->GetObject(strPath, &pObject)))
  133. {
  134. pWMI->AppendBlankLine(aColValues, iColCount);
  135. pWMI->AddObjectToOutput(aColValues, iColCount, pObject, _T("Name, FileSize, Version"), IDS_WINSOCK1);
  136. delete pObject;
  137. }
  138. }
  139. return S_OK;
  140. }
  141. //-----------------------------------------------------------------------------
  142. // This function gathers Disk information.
  143. //
  144. // TBD - might be nice to get the partition drive letter from
  145. // Win32_LogicalDiskToPartition.
  146. //-----------------------------------------------------------------------------
  147. HRESULT Disks(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  148. {
  149. ASSERT(pWMI == NULL || aColValues);
  150. if (pWMI == NULL)
  151. return S_OK;
  152. LPCTSTR szDiskProperties = _T("Description, Manufacturer, Model, MSIAdvancedBytesPerSector, MediaLoaded, MediaType, Partitions, MSIAdvancedSCSIBus, MSIAdvancedSCSILogicalUnit, MSIAdvancedSCSIPort, MSIAdvancedSCSITargetId, MSIAdvancedSectorsPerTrack, Size, MSIAdvancedTotalCylinders, MSIAdvancedTotalSectors, MSIAdvancedTotalTracks, MSIAdvancedTracksPerCylinder, MSIAdvancedPNPDeviceID, MSIAdvancedIndex");
  153. LPCTSTR szPartitionProperties = _T("Caption, Size, MSIAdvancedStartingOffset, MSIAdvancedDiskIndex");
  154. CWMIObjectCollection * pDiskCollection = NULL;
  155. HRESULT hr = pWMI->Enumerate(_T("Win32_DiskDrive"), &pDiskCollection, szDiskProperties);
  156. if (SUCCEEDED(hr))
  157. {
  158. CWMIObject * pDiskObject = NULL;
  159. while (S_OK == pDiskCollection->GetNext(&pDiskObject))
  160. {
  161. pWMI->AppendBlankLine(aColValues, iColCount);
  162. pWMI->AddObjectToOutput(aColValues, iColCount, pDiskObject, szDiskProperties, IDS_DISKS1);
  163. DWORD dwIndex;
  164. if (FAILED(pDiskObject->GetValueDWORD(_T("Index"), &dwIndex)))
  165. continue;
  166. CWMIObjectCollection * pPartitionCollection = NULL;
  167. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_DiskPartition"), &pPartitionCollection, szPartitionProperties)))
  168. {
  169. CWMIObject * pPartitionObject = NULL;
  170. while (S_OK == pPartitionCollection->GetNext(&pPartitionObject))
  171. {
  172. DWORD dwDiskIndex;
  173. if (FAILED(pPartitionObject->GetValueDWORD(_T("DiskIndex"), &dwDiskIndex)) || dwIndex != dwDiskIndex)
  174. continue;
  175. pWMI->AddObjectToOutput(aColValues, iColCount, pPartitionObject, szPartitionProperties, IDS_DISKS2);
  176. }
  177. delete pPartitionObject;
  178. delete pPartitionCollection;
  179. }
  180. }
  181. delete pDiskObject;
  182. delete pDiskCollection;
  183. }
  184. return hr;
  185. }
  186. //-----------------------------------------------------------------------------
  187. // This function gathers Problem Device information.
  188. //-----------------------------------------------------------------------------
  189. HRESULT ProblemDevices(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  190. {
  191. ASSERT(pWMI == NULL || aColValues);
  192. if (pWMI == NULL)
  193. return S_OK;
  194. CWMIObjectCollection * pCollection = NULL;
  195. HRESULT hr = pWMI->Enumerate(_T("Win32_PnPEntity"), &pCollection, _T("Caption, PNPDeviceID, ConfigManagerErrorCode"));
  196. if (SUCCEEDED(hr))
  197. {
  198. CWMIObject * pObject = NULL;
  199. while (S_OK == pCollection->GetNext(&pObject))
  200. {
  201. DWORD dwError;
  202. if (SUCCEEDED(pObject->GetValueDWORD(_T("ConfigManagerErrorCode"), &dwError)))
  203. if (dwError)
  204. pWMI->AddObjectToOutput(aColValues, iColCount, pObject, _T("Caption, PNPDeviceID, ConfigManagerErrorCode"), IDS_PROBLEMDEVICE1);
  205. }
  206. delete pObject;
  207. delete pCollection;
  208. }
  209. return hr;
  210. }
  211. //-----------------------------------------------------------------------------
  212. // This function gathers USB information.
  213. //-----------------------------------------------------------------------------
  214. HRESULT ComponentsUSB(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  215. {
  216. ASSERT(pWMI == NULL || aColValues);
  217. if (pWMI == NULL)
  218. return S_OK;
  219. CWMIObjectCollection * pUSBControllerCollection = NULL;
  220. HRESULT hr = pWMI->Enumerate(_T("Win32_USBController"), &pUSBControllerCollection, _T("Caption, PNPDeviceID, __PATH"));
  221. if (SUCCEEDED(hr))
  222. {
  223. CWMIObject * pUSBControllerObject = NULL;
  224. while (S_OK == pUSBControllerCollection->GetNext(&pUSBControllerObject))
  225. {
  226. pWMI->AddObjectToOutput(aColValues, iColCount, pUSBControllerObject, _T("Caption, PNPDeviceID"), IDS_USB1);
  227. // For each USB controller, look for devices connected to it (through
  228. // the Win32_USBControllerDevice class).
  229. CString strUSBControllerPath = pUSBControllerObject->GetString(_T("__PATH"));
  230. if (!strUSBControllerPath.IsEmpty())
  231. {
  232. CWMIObjectCollection * pAssocCollection = NULL;
  233. if (SUCCEEDED(pWMI->Enumerate(_T("Win32_USBControllerDevice"), &pAssocCollection)))
  234. {
  235. CWMIObject * pAssocObject = NULL;
  236. while (S_OK == pAssocCollection->GetNext(&pAssocObject))
  237. {
  238. CString strAntecedent, strDependent;
  239. if (SUCCEEDED(pAssocObject->GetValueString(_T("Antecedent"), &strAntecedent)))
  240. {
  241. if (strAntecedent.CompareNoCase(strUSBControllerPath) == 0)
  242. {
  243. if (SUCCEEDED(pAssocObject->GetValueString(_T("Dependent"), &strDependent)))
  244. {
  245. CWMIObject * pDeviceObject;
  246. if (SUCCEEDED(pWMI->GetObject(strDependent, &pDeviceObject)))
  247. {
  248. pWMI->AddObjectToOutput(aColValues, iColCount, pDeviceObject, _T("Caption, PNPDeviceID"), IDS_USB1);
  249. delete pDeviceObject;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. delete pAssocObject;
  256. delete pAssocCollection;
  257. }
  258. }
  259. }
  260. delete pUSBControllerObject;
  261. delete pUSBControllerCollection;
  262. }
  263. return hr;
  264. }