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.

378 lines
9.0 KiB

  1. // File System.inl
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03-15-00 v-marfin : bug 60291
  6. // Fix for HM Version display. Read properties for Major and minor version
  7. // as strings instead of ints.
  8. // 03/16/00 v-marfin : bug 60291 (Additional) : Added buildversion and hotfix version to the
  9. // healthmon version string.
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // WMI Operations
  15. /////////////////////////////////////////////////////////////////////////////
  16. inline HRESULT CSystem::Connect()
  17. {
  18. TRACEX(_T("CSystem::EnumerateChildren\n"));
  19. if( m_pSListener == NULL )
  20. {
  21. m_pSListener = new CSystemConfigListener;
  22. m_pSListener->SetObjectPtr(this);
  23. m_pSListener->Create();
  24. }
  25. if( m_pCreationListener == NULL )
  26. {
  27. m_pCreationListener = new CConfigCreationListener;
  28. m_pCreationListener->SetObjectPtr(this);
  29. m_pCreationListener->Create();
  30. }
  31. if( m_pDeletionListener == NULL )
  32. {
  33. m_pDeletionListener = new CConfigDeletionListener;
  34. m_pDeletionListener->SetObjectPtr(this);
  35. m_pDeletionListener->Create();
  36. }
  37. HRESULT hr = S_OK;
  38. CString sQuery = IDS_STRING_SYSTEMCONFIG_QUERY;
  39. IWbemObjectSink* pSink = m_pSListener->GetSink();
  40. if( !CHECKHRESULT(hr = CnxExecQueryAsync(GetSystemName(),sQuery,pSink)) )
  41. {
  42. TRACE(_T("FAILED : CConnectionManager::RegisterEventNotification failed!\n"));
  43. }
  44. return hr;
  45. }
  46. inline HRESULT CSystem::EnumerateChildren()
  47. {
  48. TRACEX(_T("CSystem::EnumerateChildren\n"));
  49. if( m_pDGListener == NULL )
  50. {
  51. m_pDGListener = new CDataGroupConfigListener;
  52. m_pDGListener->SetObjectPtr(this);
  53. m_pDGListener->Create();
  54. }
  55. else
  56. {
  57. IncrementActiveSinkCount();
  58. }
  59. HRESULT hr = S_OK;
  60. CString sQuery;
  61. sQuery.Format(IDS_STRING_S2DG_ASSOC_QUERY,GetGuid());
  62. IWbemObjectSink* pSink = m_pDGListener->GetSink();
  63. if( !CHECKHRESULT(hr = CnxExecQueryAsync(GetSystemName(),sQuery,pSink)) )
  64. {
  65. TRACE(_T("FAILED : CConnectionManager::RegisterEventNotification failed!\n"));
  66. }
  67. return hr;
  68. }
  69. inline CString CSystem::GetObjectPath()
  70. {
  71. TRACEX(_T("CSystem::GetObjectPath\n"));
  72. return IDS_STRING_MOF_SYSTEMOBJECTPATH;
  73. }
  74. inline CString CSystem::GetStatusObjectPath()
  75. {
  76. TRACEX(_T("CSystem::GetStatusObjectPath\n"));
  77. return IDS_STRING_MOF_SYSTEMSTATUSOBJECTPATH;
  78. }
  79. inline CHMEvent* CSystem::GetStatusClassObject()
  80. {
  81. TRACEX(_T("CSystem::GetStatusClassObject\n"));
  82. CHMEvent* pClassObject = new CHMSystemStatus;
  83. pClassObject->SetMachineName(GetSystemName());
  84. if( ! CHECKHRESULT(pClassObject->GetObject(GetStatusObjectPath())) )
  85. {
  86. delete pClassObject;
  87. return NULL;
  88. }
  89. pClassObject->GetAllProperties();
  90. return pClassObject;
  91. }
  92. inline void CSystem::GetWMIVersion(CString& sVersion)
  93. {
  94. TRACEX(_T("CSystem::GetWMIVersion\n"));
  95. sVersion.Empty();
  96. CWbemClassObject IdObject;
  97. CString sNamespace = _T("\\\\") + GetSystemName() + _T("\\root\\cimv2");
  98. IdObject.SetNamespace(sNamespace);
  99. HRESULT hr = IdObject.GetObject(_T("__CIMOMIdentification"));
  100. if( ! CHECKHRESULT(hr) )
  101. {
  102. return;
  103. }
  104. IdObject.GetProperty(_T("VersionUsedToCreateDB"),sVersion);
  105. IdObject.Destroy();
  106. IdObject.SetNamespace(sNamespace);
  107. hr = IdObject.GetObject(_T("Win32_WMISetting=@"));
  108. if( ! CHECKHRESULT(hr) )
  109. {
  110. return;
  111. }
  112. CString sBuildVersion;
  113. IdObject.GetProperty(_T("BuildVersion"),sBuildVersion);
  114. sVersion = sVersion.Left(5);
  115. sVersion += sBuildVersion;
  116. }
  117. inline void CSystem::GetHMAgentVersion(CString& sVersion)
  118. {
  119. TRACEX(_T("CSystem::GetHMAgentVersion\n"));
  120. sVersion.Empty();
  121. CWbemClassObject HMVersionObject;
  122. CString sNamespace;
  123. sNamespace.Format(IDS_STRING_HEALTHMON_ROOT, GetSystemName());
  124. HMVersionObject.SetNamespace(sNamespace);
  125. HRESULT hr = HMVersionObject.GetObject(_T("Microsoft_HMVersion=@"));
  126. if( ! CHECKHRESULT(hr) )
  127. {
  128. return;
  129. }
  130. // v-marfin : bug 60291
  131. // Fix for HM Version display. Read properties for Major and minor version
  132. // as strings instead of ints.
  133. /*int iMajorVersion = 0;
  134. int iMinorVersion = 0;
  135. HMVersionObject.GetProperty(_T("iMajorVersion"),iMajorVersion);
  136. HMVersionObject.GetProperty(_T("iMinorVersion"),iMinorVersion);
  137. sVersion.Format(_T("%d.%d"),iMajorVersion,iMinorVersion);*/
  138. // v-marfin : bug 60291 (Additional) Added build number and hotfix number to version string
  139. CString sMajorVersion = _T("0");
  140. CString sMinorVersion = _T("0");
  141. CString sBuildVersion = _T("0");
  142. CString sHotfixVersion = _T("0");
  143. HMVersionObject.GetProperty(_T("MajorVersion"),sMajorVersion);
  144. HMVersionObject.GetProperty(_T("MinorVersion"),sMinorVersion);
  145. HMVersionObject.GetProperty(_T("BuildVersion"),sBuildVersion);
  146. HMVersionObject.GetProperty(_T("HotfixVersion"),sHotfixVersion);
  147. sVersion.Format(_T("%s.%s.%s.%s"),sMajorVersion,sMinorVersion,sBuildVersion,sHotfixVersion);
  148. }
  149. inline BOOL CSystem::GetComputerSystemInfo(CString& sDomain, CString& sProcessor)
  150. {
  151. TRACEX(_T("CSystem::GetComputerSystemInfo\n"));
  152. // query for the Win32_ComputerSystem class instances
  153. CWbemClassObject SystemInfo;
  154. SystemInfo.SetNamespace(_T("\\\\") + GetSystemName() + _T("\\root\\cimv2"));
  155. if( ! CHECKHRESULT(SystemInfo.Create(GetSystemName())) )
  156. {
  157. return FALSE;
  158. }
  159. CString sTemp;
  160. sTemp.Format(_T("Win32_ComputerSystem.Name=\"%s\""),GetSystemName());
  161. if( ! CHECKHRESULT(SystemInfo.GetObject(sTemp)) )
  162. {
  163. // return;
  164. return FALSE; // v-marfin 62501
  165. }
  166. // read in the Domain
  167. SystemInfo.GetProperty(_T("Domain"),sDomain);
  168. // read in the SystemType
  169. SystemInfo.GetProperty(_T("SystemType"),sProcessor);
  170. return TRUE; // v-marfin 62501
  171. }
  172. inline void CSystem::GetOperatingSystemInfo(CString& sOSInfo)
  173. {
  174. TRACEX(_T("CSystem::GetOperatingSystemInfo\n"));
  175. // query for the Win32_OperatingSystem class instances
  176. CWbemClassObject SystemInfo;
  177. SystemInfo.SetNamespace(_T("\\\\") + GetSystemName() + _T("\\root\\cimv2"));
  178. CString sTemp = _T("Win32_OperatingSystem");
  179. BSTR bsTemp = sTemp.AllocSysString();
  180. if( ! CHECKHRESULT(SystemInfo.CreateEnumerator(bsTemp)) )
  181. {
  182. ::SysFreeString(bsTemp);
  183. return;
  184. }
  185. ::SysFreeString(bsTemp);
  186. ULONG ulReturned = 0L;
  187. if( SystemInfo.GetNextObject(ulReturned) != S_OK )
  188. {
  189. return;
  190. }
  191. // read in the caption
  192. CString sCaption;
  193. SystemInfo.GetProperty(_T("Caption"),sCaption);
  194. // read in the BuildNumber
  195. CString sBuildNumber;
  196. SystemInfo.GetProperty(_T("BuildNumber"),sBuildNumber);
  197. // read in the BuildType
  198. CString sBuildType;
  199. SystemInfo.GetProperty(_T("BuildType"),sBuildType);
  200. // read in the CSDVersion
  201. CString sCSDVersion;
  202. SystemInfo.GetProperty(_T("CSDVersion"),sCSDVersion);
  203. sOSInfo.Format(IDS_STRING_SYSINFO_FORMAT,sCaption,sBuildNumber,sBuildType,sCSDVersion);
  204. }
  205. /////////////////////////////////////////////////////////////////////////////
  206. // Clipboard Operations
  207. /////////////////////////////////////////////////////////////////////////////
  208. inline bool CSystem::Cut()
  209. {
  210. TRACEX(_T("CSystem::Cut\n"));
  211. return false;
  212. }
  213. inline bool CSystem::Copy()
  214. {
  215. TRACEX(_T("CSystem::Copy\n"));
  216. return false;
  217. }
  218. inline bool CSystem::Paste()
  219. {
  220. TRACEX(_T("CSystem::Paste\n"));
  221. return false;
  222. }
  223. /////////////////////////////////////////////////////////////////////////////
  224. // Operations
  225. /////////////////////////////////////////////////////////////////////////////
  226. inline void CSystem::Serialize(CArchive& ar)
  227. {
  228. TRACEX(_T("CSystem::Serialize\n"));
  229. CHMObject::Serialize(ar);
  230. if( ar.IsStoring() )
  231. {
  232. ar << GetSystemName();
  233. }
  234. else
  235. {
  236. CString sName;
  237. ar >> sName;
  238. SetSystemName(sName);
  239. // ping the machine first...adds the system to the lookup table in ConnMgr
  240. IWbemServices* pIServices = NULL;
  241. BOOL bAvail;
  242. HRESULT hr = CnxGetConnection(sName,pIServices,bAvail);
  243. if( pIServices )
  244. {
  245. pIServices->Release();
  246. }
  247. //--------------------------
  248. // Caller will inspect system name to see if serialize was successful
  249. // v-marfin 62501
  250. if( ! CHECKHRESULT(hr) )
  251. {
  252. CString sFailed = GetSystemName() + FAILED_STRING;
  253. SetSystemName(sFailed);
  254. return;
  255. }
  256. //--------------------------
  257. }
  258. }
  259. /////////////////////////////////////////////////////////////////////////////
  260. // Scope Item Members
  261. /////////////////////////////////////////////////////////////////////////////
  262. inline CScopePaneItem* CSystem::CreateScopeItem()
  263. {
  264. TRACEX(_T("CSystem::CreateScopeItem\n"));
  265. CSystemScopeItem * pNewItem = new CSystemScopeItem;
  266. pNewItem->SetObjectPtr(this);
  267. return pNewItem;
  268. }
  269. /////////////////////////////////////////////////////////////////////////////
  270. // New Child Creation Members
  271. /////////////////////////////////////////////////////////////////////////////
  272. inline void CSystem::CreateNewChildDataGroup()
  273. {
  274. TRACEX(_T("CSystem::CreateNewChildDataGroup\n"));
  275. CString sName = GetUniqueChildName(IDS_STRING_DATA_GROUP_FMT);
  276. CDataGroup* pNewGroup = new CDataGroup;
  277. pNewGroup->SetName(sName);
  278. CreateChild(pNewGroup,IDS_STRING_MOF_HMDG_CONFIG,IDS_STRING_MOF_HMC2C_ASSOC);
  279. if( pNewGroup->GetScopeItemCount() )
  280. {
  281. CScopePaneItem* pItem = pNewGroup->GetScopeItem(0);
  282. if( pItem )
  283. {
  284. pItem->SelectItem();
  285. pItem->InvokePropertySheet();
  286. }
  287. }
  288. }