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.

1044 lines
43 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. .PCH_SysInfo.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_SysInfo class.
  7. 1. This class gets the foll. properties from Win32_OperatingSystem Class:
  8. "OSName", "Version"
  9. and sets "PCH_SysInfo.OsName" property.
  10. 2. Gets the foll. properties from Win32_Processor Class:
  11. "Manufacturer", "Description"
  12. and sets "PCH_SysInfo.Processor" property.
  13. 3. Gets the foll. properties from Win32_LogicalMemoryConfiguration Class:
  14. "TotalPhysicalMemory"
  15. and sets "PCH_SysInfo.RAM" property.
  16. 4. Gets the foll. properties from Win32_PageFile Class:
  17. "Name", "FreeSpace", "FSName"
  18. and sets PCH_SysInfo.SwapFile Property.
  19. 5. Sets the "Change" property to "Snapshot" always
  20. Revision History:
  21. Ghim Sim Chua (gschua ) 04/27/99
  22. - Created
  23. Kalyani Narlanka (kalyanin) 05/03/99
  24. - Added properties
  25. *******************************************************************************/
  26. #include "pchealth.h"
  27. #include "PCH_Sysinfo.h"
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // Begin Tracing stuff
  30. //
  31. #ifdef THIS_FILE
  32. #undef THIS_FILE
  33. #endif
  34. static char __szTraceSourceFile[] = __FILE__;
  35. #define THIS_FILE __szTraceSourceFile
  36. #define TRACE_ID DCID_SYSINFO
  37. //
  38. // End Tracing stuff
  39. ///////////////////////////////////////////////////////////////////////////////
  40. CPCH_Sysinfo MyPCH_SysinfoSet (PROVIDER_NAME_PCH_SYSINFO, PCH_NAMESPACE) ;
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // Different types of Installation
  43. #define IDS_SKU_NET "network"
  44. #define IDS_SKU_CD_UPGRADE "CD"
  45. #define IDS_SKU_FLOPPY_UPGRADE "Floppy"
  46. #define IDS_SKU_FLOPPY_FULL "Full Floppy"
  47. #define IDS_SKU_SELECT_FLOPPY "floppy"
  48. #define IDS_SKU_SELECT_CD "Select CD"
  49. #define IDS_SKU_OEM_DISKMAKER "OEM"
  50. #define IDS_SKU_OEM_FLOPPY "OEM floppy"
  51. #define IDS_SKU_OEM_CD "OEM CD"
  52. #define IDS_SKU_MS_INTERNAL "Microsoft Internal"
  53. #define IDS_SKU_CD_FULL "Full CD"
  54. #define IDS_SKU_WEB "Web"
  55. #define IDS_SKU_MSDN_CD "MSDN CD"
  56. #define IDS_SKU_OEM_CD_FULL "Full OEM CD"
  57. #define IDS_SKU_OEM_PREINST_KIT "OEM Preinstall Kit"
  58. #define MAX_LEN 20
  59. #define ONEK 1024
  60. #define HALFK 512
  61. //....Properties of PCHSysInfo Class
  62. //
  63. const static WCHAR* pOSLanguage = L"OSLanguage";
  64. const static WCHAR* pManufacturer = L"Manufacturer";
  65. const static WCHAR* pModel = L"Model";
  66. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  67. const static WCHAR* pChange = L"Change" ;
  68. const static WCHAR* pIEVersion = L"IEVersion" ;
  69. const static WCHAR* pInstall = L"Install" ;
  70. const static WCHAR* pMode = L"Mode" ;
  71. const static WCHAR* pOSName = L"OSName" ;
  72. const static WCHAR* pOSVersion = L"OSVersion";
  73. const static WCHAR* pProcessor = L"Processor" ;
  74. const static WCHAR* pClockSpeed = L"ClockSpeed" ;
  75. const static WCHAR* pRAM = L"RAM" ;
  76. const static WCHAR* pSwapFile = L"SwapFile" ;
  77. const static WCHAR* pSystemID = L"SystemID" ;
  78. const static WCHAR* pUptime = L"Uptime" ;
  79. const static WCHAR* pOSBuildNumber = L"OSBuildNumber";
  80. //*****************************************************************************
  81. //
  82. // Function Name : CPCH_SysInfo::EnumerateInstances
  83. //
  84. // Input Parameters : pMethodContext : Pointer to the MethodContext for
  85. // communication with WinMgmt.
  86. //
  87. // lFlags : Long that contains the flags described
  88. // in IWbemServices::CreateInstanceEnumAsync
  89. // Note that the following flags are handled
  90. // by (and filtered out by) WinMgmt:
  91. // WBEM_FLAG_DEEP
  92. // WBEM_FLAG_SHALLOW
  93. // WBEM_FLAG_RETURN_IMMEDIATELY
  94. // WBEM_FLAG_FORWARD_ONLY
  95. // WBEM_FLAG_BIDIRECTIONAL
  96. // Output Parameters : None
  97. //
  98. // Returns : WBEM_S_NO_ERROR
  99. //
  100. //
  101. // Synopsis : All instances of this class on the machine are returned.
  102. // If there are no instances returns WBEM_S_NO_ERROR.
  103. // It is not an error to have no instances.
  104. //
  105. //
  106. //*****************************************************************************
  107. HRESULT CPCH_Sysinfo::EnumerateInstances(MethodContext* pMethodContext,
  108. long lFlags)
  109. {
  110. TraceFunctEnter("CPCH_Sysinfo::EnumerateInstances");
  111. // Begin Declarations...................................................
  112. //
  113. HRESULT hRes = WBEM_S_NO_ERROR;
  114. // Instances
  115. CComPtr<IEnumWbemClassObject> pOperatingSystemEnumInst;
  116. CComPtr<IEnumWbemClassObject> pProcessorEnumInst;
  117. CComPtr<IEnumWbemClassObject> pLogicalMemConfigEnumInst;
  118. CComPtr<IEnumWbemClassObject> pPageFileEnumInst;
  119. CComPtr<IEnumWbemClassObject> pComputerSystemEnumInst;
  120. // CInstance *pPCHSysInfoInstance;
  121. // WBEM Objects
  122. IWbemClassObjectPtr pOperatingSystemObj; // BUGBUG : WMI asserts if we use CComPtr
  123. IWbemClassObjectPtr pProcessorObj; // BUGBUG : WMI asserts if we use CComPtr
  124. IWbemClassObjectPtr pLogicalMemConfigObj; // BUGBUG : WMI asserts if we use CComPtr
  125. IWbemClassObjectPtr pPageFileObj; // BUGBUG : WMI asserts if we use CComPtr
  126. IWbemClassObjectPtr pComputerSystemObj; // BUGBUG : WMI asserts if we use CComPtr
  127. // Variants
  128. CComVariant varValue;
  129. CComVariant varCaption;
  130. CComVariant varVersion;
  131. CComVariant varSnapshot = "Snapshot";
  132. CComVariant varRam;
  133. CComVariant varPhysicalMem;
  134. // Return Values
  135. ULONG ulOperatingSystemRetVal;
  136. ULONG ulProcessorRetVal;
  137. ULONG ulLogicalMemConfigRetVal;
  138. ULONG ulPageFileRetVal;
  139. ULONG ulComputerSystemRetVal;
  140. LONG lRegKeyRet;
  141. LONG lSystemID;
  142. // Query Strings
  143. CComBSTR bstrOperatingSystemQuery = L"Select Caption, Version, Name, OSLanguage, BuildNumber FROM Win32_OperatingSystem";
  144. CComBSTR bstrProcessorQuery = L"Select DeviceID, Name, Manufacturer, CurrentClockSpeed FROM Win32_Processor";
  145. CComBSTR bstrLogicalMemConfigQuery = L"Select Name, TotalPhysicalMemory FROM Win32_LogicalMemoryConfiguration";
  146. CComBSTR bstrPageFileQuery = L"Select Name, FreeSpace, FSName FROM Win32_PageFile";
  147. CComBSTR bstrComputerSystemQuery = L"Select Name, BootupState, Manufacturer, Model FROM Win32_ComputerSystem";
  148. CComBSTR bstrQueryString;
  149. CComBSTR bstrProperty;
  150. CComBSTR bstrVersion = L"Version";
  151. CComBSTR bstrCaption = L"Caption";
  152. CComBSTR bstrManufacturer = L"Manufacturer";
  153. CComBSTR bstrModel = L"Model";
  154. CComBSTR bstrOSLanguage = L"OSLanguage";
  155. CComBSTR bstrName = L"Name";
  156. CComBSTR bstrFreeSpace = L"FreeSpace";
  157. CComBSTR bstrFSName = L"FSName";
  158. CComBSTR bstrBuildNumber = L"BuildNumber";
  159. CComBSTR bstrSemiColon = L" ; ";
  160. LPCTSTR lpctstrSpaces = " ";
  161. LPCTSTR lpctstrCleanInstall = _T("Clean Install Using");
  162. LPCTSTR lpctstrUpgradeInstall = _T("Upgrade Using");
  163. CComBSTR bstrProcessor;
  164. CComBSTR bstrOSName;
  165. CComBSTR bstrSwapFile;
  166. // Registry Hive where IE info is stored
  167. LPCTSTR lpctstrIEHive = _T("Software\\Microsoft\\windows\\currentversion");
  168. LPCTSTR lpctstrSystemIDHive = _T("Software\\Microsoft\\PCHealth\\MachineInfo");
  169. LPCTSTR lpctstrUpgrade = _T("Upgrade");
  170. LPCTSTR lpctstrProductType = _T("ProductType");
  171. LPCTSTR lpctstrCommandLine = _T("CommandLine");
  172. LPCTSTR lpctstrIEVersion = _T("Plus! VersionNumber");
  173. LPCWSTR lpctstrVersion = L"Version";
  174. LPCWSTR lpctstrBootupState = L"BootupState";
  175. LPCWSTR lpctstrTotalPhysicalMemory = L"TotalPhysicalMemory";
  176. LPCTSTR lpctstrComputerName = _T("ComputerName");
  177. LPCTSTR lpctstrCurrentUser = _T("Current User");
  178. LPCTSTR lpctstrMBFree = _T(" MB Free ");
  179. LPCWSTR lpctstrClockSpeed = L"CurrentClockSpeed";
  180. LPCWSTR lpctstrCaption = L"Name";
  181. // Format Strings
  182. LPCTSTR lpctstrSystemIDFormat = _T("On \"%s\" as \"%s\"");
  183. LPCTSTR lpctstrOSNameFormat = _T("%s %s");
  184. LPCTSTR lpctstrInstallFormat = _T("%s %s %s");
  185. LPCTSTR lpctstrUptimeFormat = _T("%d:%02d:%02d:%02d");
  186. LPCSTR lpctstrInstallHive = "Software\\Microsoft\\Windows\\CurrentVersion\\Setup";
  187. LPCSTR lpctstrCurrentVersionHive = "Software\\Microsoft\\Windows\\CurrentVersion";
  188. LPCSTR lpctstrControlHive = "System\\CurrentControlSet\\Control";
  189. LPCTSTR lpctstrPID = _T("PID");
  190. LPCTSTR lpctstrNoSystemID = _T("NoSystemID");
  191. // Other Strings
  192. TCHAR tchIEVersionValue[MAX_LEN];
  193. TCHAR tchCommandLineValue[MAX_PATH];
  194. TCHAR tchProductTypeValue[MAX_LEN];
  195. TCHAR tchCurrentUserValue[MAX_PATH];
  196. TCHAR tchComputerNameValue[MAX_PATH];
  197. TCHAR tchSystemID[MAX_PATH];
  198. TCHAR tchOSName[MAX_PATH];
  199. TCHAR tchInstallStr[3*MAX_PATH];
  200. TCHAR tchUptimeStr[MAX_PATH];
  201. TCHAR tchInstall[MAX_PATH];
  202. TCHAR tchProductType[MAX_PATH];
  203. // Time
  204. SYSTEMTIME stUTCTime;
  205. // DWORD
  206. DWORD dwSize = MAX_PATH;
  207. DWORD dwType;
  208. // Key
  209. HKEY hkeyIEKey;
  210. HKEY hkeyInstallKey;
  211. HKEY hkeyCurrentVersionKey;
  212. HKEY hkeyComputerKey;
  213. HKEY hkeyComputerSubKey;
  214. HKEY hkeyControlKey;
  215. HKEY hkeySystemIDKey;
  216. BYTE bUpgradeValue;
  217. int nProductTypeValue;
  218. int nStrLen;
  219. int nDays, nHours, nMins, nSecs;
  220. int nRam, nRem;
  221. float dRam;
  222. BOOL fCommit = FALSE;
  223. // End Declarations...................................................
  224. // Initializations
  225. tchIEVersionValue[0] = 0;
  226. tchCommandLineValue[0] = 0;
  227. tchProductTypeValue[0] = 0;
  228. tchProductType[0] = 0;
  229. tchCurrentUserValue[0] = 0;
  230. tchComputerNameValue[0] = 0;
  231. tchSystemID[0] = 0;
  232. tchInstallStr[0] = 0;
  233. varValue.Clear();
  234. varCaption.Clear();
  235. varVersion.Clear();
  236. //
  237. // Get the date and time This is required for the TimeStamp field
  238. GetSystemTime(&stUTCTime);
  239. // Create a new instance of PCH_SysInfo Class based on the
  240. // passed-in MethodContext
  241. CInstancePtr pPCHSysInfoInstance(CreateNewInstance(pMethodContext), false);
  242. // Created a New Instance of PCH_SysInfo Successfully.
  243. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  244. // TIME STAMP //
  245. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  246. hRes = pPCHSysInfoInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime));
  247. if (FAILED(hRes))
  248. {
  249. // Could not Set the Time Stamp
  250. // Continue anyway
  251. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  252. }
  253. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  254. // CHANGE //
  255. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. hRes = pPCHSysInfoInstance->SetVariant(pChange, varSnapshot);
  257. if (FAILED(hRes))
  258. {
  259. // Could not Set the Change Property
  260. // Continue anyway
  261. ErrorTrace(TRACE_ID, "Set Variant on Change Field failed.");
  262. }
  263. // To fix the Bug : 100158 : the system ID property should not contain any privacy info.
  264. // In its place we generate some random number;
  265. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  266. // SYSTEMID //
  267. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  268. // The SystemID can be obtained from HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\COMPUTERNAME\COMPUTERNAME
  269. // The username can be obtained from HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\CURRENTUSER
  270. //
  271. /*
  272. lRegKeyRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpctstrControlHive, 0, KEY_READ, &hkeyControlKey);
  273. if(lRegKeyRet == ERROR_SUCCESS)
  274. {
  275. // Opened the Control Key
  276. // Open the Computer System sub key under hkeyControlKey
  277. lRegKeyRet = RegOpenKeyEx(hkeyControlKey, lpctstrComputerName, 0, KEY_READ, &hkeyComputerKey);
  278. if(lRegKeyRet == ERROR_SUCCESS)
  279. {
  280. // Opened the ComputerNameSub Key
  281. // Open the
  282. // Open the CompterNameSubSubKey key under ComputerNameSub Key
  283. lRegKeyRet = RegOpenKeyEx(hkeyComputerKey, lpctstrComputerName, 0, KEY_READ, &hkeyComputerSubKey);
  284. if(lRegKeyRet == ERROR_SUCCESS)
  285. {
  286. // Read the ComputerName Value
  287. dwSize = MAX_PATH;
  288. lRegKeyRet = RegQueryValueEx(hkeyComputerSubKey, lpctstrComputerName, NULL, &dwType, (LPBYTE)tchComputerNameValue, &dwSize);
  289. if (lRegKeyRet != ERROR_SUCCESS)
  290. {
  291. // Could not get the ComputerName
  292. ErrorTrace(TRACE_ID, "Cannot get the ComputerName");
  293. }
  294. // Close the ComputerName Sub Sub Key
  295. lRegKeyRet = RegCloseKey(hkeyComputerSubKey);
  296. if(lRegKeyRet != ERROR_SUCCESS)
  297. {
  298. // Could not close the key.
  299. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  300. }
  301. }
  302. // Close the ComputerName Sub Key
  303. lRegKeyRet = RegCloseKey(hkeyComputerKey);
  304. if(lRegKeyRet != ERROR_SUCCESS)
  305. {
  306. // Could not close the key.
  307. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  308. }
  309. }
  310. // Read the CurrentUser Value
  311. dwSize = MAX_PATH;
  312. lRegKeyRet = RegQueryValueEx(hkeyControlKey, lpctstrCurrentUser, NULL, &dwType, (LPBYTE)tchCurrentUserValue, &dwSize);
  313. if (lRegKeyRet != ERROR_SUCCESS)
  314. {
  315. // Could not get the UserName
  316. ErrorTrace(TRACE_ID, "Cannot get the UserName");
  317. }
  318. // Close the Control Key
  319. lRegKeyRet = RegCloseKey(hkeyControlKey);
  320. if(lRegKeyRet != ERROR_SUCCESS)
  321. {
  322. // Could not close the key.
  323. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  324. }
  325. // Got the ComputerName and CurrentUser, Format the string for systemID.
  326. nStrLen = wsprintf(tchSystemID,lpctstrSystemIDFormat, tchComputerNameValue, tchCurrentUserValue);
  327. lSystemID = long(GetTickCount());
  328. _ltot(lSystemID, tchSystemID, 10);
  329. // Set the SystemID Property
  330. varValue = tchSystemID;
  331. if (FAILED(pPCHSysInfoInstance->SetVariant(pSystemID, varValue)))
  332. {
  333. // Set SystemID Field Failed.
  334. // Proceed anyway
  335. ErrorTrace(TRACE_ID, "SetVariant on OSName Field failed.");
  336. }
  337. else
  338. {
  339. fCommit = TRUE;
  340. }
  341. }
  342. */
  343. /*
  344. lSystemID = long(GetTickCount());
  345. _ltot(lSystemID, tchSystemID, 10);
  346. */
  347. // To fix Bug 100268 , get the system ID from the Registry.
  348. // The Registry key to read is :
  349. // HKLM\SW\MS\PCHealth\MachineInfo\PID
  350. lRegKeyRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpctstrSystemIDHive, 0, KEY_READ, &hkeySystemIDKey);
  351. if(lRegKeyRet == ERROR_SUCCESS)
  352. {
  353. // Opened the SystemID Hive
  354. // Read the PID Value
  355. dwSize = MAX_PATH;
  356. lRegKeyRet = RegQueryValueEx(hkeySystemIDKey, lpctstrPID, NULL, &dwType, (LPBYTE)tchSystemID, &dwSize);
  357. if (lRegKeyRet != ERROR_SUCCESS)
  358. {
  359. _tcscpy(tchSystemID,lpctstrNoSystemID);
  360. // Could not get the PID
  361. ErrorTrace(TRACE_ID, "Cannot get the PID");
  362. }
  363. // Close the SystemID Key
  364. lRegKeyRet = RegCloseKey(hkeySystemIDKey);
  365. if(lRegKeyRet != ERROR_SUCCESS)
  366. {
  367. // Could not close the key.
  368. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  369. }
  370. }
  371. // Set the SystemID Property
  372. varValue = tchSystemID;
  373. if (FAILED(pPCHSysInfoInstance->SetVariant(pSystemID, varValue)))
  374. {
  375. // Set SystemID Field Failed.
  376. // Proceed anyway
  377. ErrorTrace(TRACE_ID, "SetVariant on OSName Field failed.");
  378. }
  379. else
  380. {
  381. fCommit = TRUE;
  382. }
  383. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  384. // OSNAME //
  385. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  386. // Execute the query to get "Caption", "Version", "Name" from Win32_OperatingSystem Class.
  387. // Although "Name" is not required to set PCH_SysInfo.OSName property
  388. // we need to query for it as its the "Key" property of the class.
  389. // pOperatingSystemEnumInst contains a pointer to the list of instances returned.
  390. //
  391. hRes = ExecWQLQuery(&pOperatingSystemEnumInst, bstrOperatingSystemQuery);
  392. if (SUCCEEDED(hRes))
  393. {
  394. // Query on Win32_OperatingSystem Class Succeeded
  395. // Enumerate the instances of Win32_OperatingSystem Class
  396. // from pOperatingSystemEnumInst.
  397. // Get the next instance into pOperatingSystemObj object.
  398. hRes = pOperatingSystemEnumInst->Next(WBEM_INFINITE, 1, &pOperatingSystemObj, &ulOperatingSystemRetVal);
  399. if(hRes == WBEM_S_NO_ERROR)
  400. {
  401. // Copy property "caption" to "OSName"
  402. CopyProperty(pOperatingSystemObj, lpctstrCaption, pPCHSysInfoInstance, pOSName);
  403. // Copy property "Version" to "Version"
  404. CopyProperty(pOperatingSystemObj, lpctstrVersion, pPCHSysInfoInstance, pOSVersion);
  405. // Copy property "OSLangauge" to "OSLangauge"
  406. CopyProperty(pOperatingSystemObj, bstrOSLanguage, pPCHSysInfoInstance, pOSLanguage);
  407. // Copy property "BuildNumber" to "BuildNumber"
  408. CopyProperty(pOperatingSystemObj, bstrBuildNumber, pPCHSysInfoInstance, pOSBuildNumber);
  409. } //end of if WBEM_S_NO_ERROR
  410. } // end of if SUCCEEDED(hRes)
  411. else
  412. {
  413. // Operating system Query did not succeed.
  414. ErrorTrace(TRACE_ID, "Query on win32_OperatingSystem Field failed.");
  415. }
  416. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  417. // UPTIME //
  418. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  419. // Get uptime using GetTickCount()
  420. dwSize = GetTickCount();
  421. /* There is a bug in the server side because of the fix and so this needs to be reverted again.
  422. // GetTickCount returns uptime in milliseconds. Divide this by 1000 to get seconds.
  423. dwSize = dwSize/1000.0;
  424. // To fix the bug of inconsistent time formats, change the seconds to days::hours::mins::secs.
  425. // Get the number of days.
  426. nDays = dwSize/(60*60*24);
  427. dwSize = dwSize%(60*60*24);
  428. // Get the Number of hours.
  429. nHours = dwSize/(60*60);
  430. dwSize = dwSize%(60*60);
  431. //Get the Number of Mins.
  432. nMins = dwSize/(60);
  433. //Get the Number of Secs.
  434. nSecs = dwSize%60;
  435. nStrLen = wsprintf(tchUptimeStr,lpctstrUptimeFormat, nDays, nHours, nMins, nSecs);
  436. varValue = tchUptimeStr;
  437. */
  438. // varValue = (long)dwSize;
  439. varValue.vt = VT_I4;
  440. varValue.lVal = (long)dwSize;
  441. // Set the UpTime Property
  442. if (FAILED(pPCHSysInfoInstance->SetVariant(pUptime, varValue)))
  443. {
  444. // Set UpTime Failed.
  445. // Proceed anyway
  446. ErrorTrace(TRACE_ID, "SetVariant on UpTime Field failed.");
  447. }
  448. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  449. // INSTALL //
  450. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  451. // The Install info is obtained from the Registry
  452. // Get "Upgrade" regvalue from HKLM\Software\Microsoft\Windows\CurrentVersion\Setup
  453. // if Upgrade == 0, then it is "Clean Install" otherwise its a "Upgrade"
  454. dwSize = MAX_PATH;
  455. lRegKeyRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpctstrInstallHive, 0, KEY_READ, &hkeyInstallKey);
  456. if(lRegKeyRet == ERROR_SUCCESS)
  457. {
  458. // Opened the Install Key
  459. // Read the upgrade Value
  460. dwSize = 1;
  461. lRegKeyRet = RegQueryValueEx(hkeyInstallKey, lpctstrUpgrade, NULL, &dwType, &bUpgradeValue, &dwSize);
  462. if (lRegKeyRet == ERROR_SUCCESS)
  463. {
  464. // Compare Install Value with "00"
  465. if (bUpgradeValue == 0)
  466. {
  467. // Clean Install
  468. _tcscpy(tchInstall, lpctstrCleanInstall);
  469. }
  470. else
  471. {
  472. _tcscpy(tchInstall, lpctstrUpgradeInstall);
  473. }
  474. }
  475. // Read the CommandLine Value
  476. dwSize = MAX_PATH;
  477. lRegKeyRet = RegQueryValueEx(hkeyInstallKey, lpctstrCommandLine, NULL, &dwType, (LPBYTE)tchCommandLineValue, &dwSize);
  478. lRegKeyRet = RegCloseKey(hkeyInstallKey);
  479. if(lRegKeyRet != ERROR_SUCCESS)
  480. {
  481. // Could not close the key.
  482. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  483. }
  484. }
  485. // Get "ProductType" regvalue from HKLM\Software\Microsoft\Windows\CurrentVersion
  486. dwSize = MAX_PATH;
  487. lRegKeyRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpctstrCurrentVersionHive, 0, KEY_READ, &hkeyCurrentVersionKey);
  488. if(lRegKeyRet == ERROR_SUCCESS)
  489. {
  490. // Opened the CurrentVersion Key
  491. // Read the ProductType Value
  492. lRegKeyRet = RegQueryValueEx(hkeyCurrentVersionKey, lpctstrProductType, NULL, &dwType, (LPBYTE)tchProductTypeValue, &dwSize);
  493. if (lRegKeyRet == ERROR_SUCCESS)
  494. {
  495. // Compare ProductType Value with known codes
  496. // Convert the productType value to an int
  497. nProductTypeValue = atoi(tchProductTypeValue);
  498. switch(nProductTypeValue)
  499. {
  500. case 100:
  501. {
  502. _tcscpy(tchProductType, IDS_SKU_MS_INTERNAL);
  503. break;
  504. }
  505. case 101:
  506. {
  507. _tcscpy(tchProductType, IDS_SKU_CD_FULL);
  508. break;
  509. }
  510. case 102:
  511. {
  512. _tcscpy(tchProductType, IDS_SKU_CD_UPGRADE);
  513. break;
  514. }
  515. case 103:
  516. {
  517. _tcscpy(tchProductType,IDS_SKU_FLOPPY_FULL);
  518. break;
  519. }
  520. case 104:
  521. {
  522. _tcscpy(tchProductType,IDS_SKU_FLOPPY_UPGRADE);
  523. break;
  524. }
  525. case 105:
  526. {
  527. _tcscpy(tchProductType,IDS_SKU_WEB);
  528. break;
  529. }
  530. case 110:
  531. {
  532. _tcscpy(tchProductType, IDS_SKU_SELECT_CD);
  533. break;
  534. }
  535. case 111:
  536. {
  537. _tcscpy(tchProductType, IDS_SKU_MSDN_CD);
  538. break;
  539. }
  540. case 115:
  541. {
  542. _tcscpy(tchProductType, IDS_SKU_OEM_CD_FULL);
  543. break;
  544. }
  545. case 116:
  546. {
  547. _tcscpy(tchProductType,IDS_SKU_OEM_CD);
  548. break;
  549. }
  550. case 120:
  551. {
  552. _tcscpy(tchProductType, IDS_SKU_OEM_PREINST_KIT);
  553. break;
  554. }
  555. case 1:
  556. {
  557. _tcscpy(tchProductType, IDS_SKU_NET);
  558. break;
  559. }
  560. case 5:
  561. {
  562. _tcscpy(tchProductType, IDS_SKU_SELECT_FLOPPY);
  563. break;
  564. }
  565. case 7:
  566. {
  567. _tcscpy(tchProductType, IDS_SKU_OEM_DISKMAKER);
  568. break;
  569. }
  570. case 8:
  571. {
  572. _tcscpy(tchProductType, IDS_SKU_OEM_FLOPPY);
  573. break;
  574. }
  575. default:
  576. {
  577. // Cannot figure out the type of installation
  578. }
  579. }
  580. }
  581. // RegCloseKey(hkeyCurrentVersionKey);
  582. lRegKeyRet = RegCloseKey(hkeyCurrentVersionKey);
  583. if(lRegKeyRet != ERROR_SUCCESS)
  584. {
  585. // Could not close the key.
  586. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  587. }
  588. }
  589. nStrLen = wsprintf(tchInstallStr,lpctstrInstallFormat, tchInstall, tchProductType, tchCommandLineValue);
  590. varValue = tchInstallStr;
  591. // Set the Install Property
  592. if (FAILED(pPCHSysInfoInstance->SetVariant(pInstall, varValue)))
  593. {
  594. // Set Install Failed.
  595. // Proceed anyway
  596. ErrorTrace(TRACE_ID, "SetVariant on OSName Field failed.");
  597. }
  598. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  599. // IEVERSION //
  600. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  601. // IE Version can be obtained from the Registry under the following hive.
  602. // HKLM\Software\Microsoft\Windows\Current Version
  603. // Version is available in the field "Plus!VersionNumber"
  604. // "Internet Explorer" Key is in "hkeyIEKey"
  605. lRegKeyRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpctstrIEHive, 0, KEY_READ, &hkeyIEKey);
  606. if(lRegKeyRet == ERROR_SUCCESS)
  607. {
  608. // Opened the Internet Explorer key.
  609. // Read the Version Value
  610. dwSize = MAX_PATH;
  611. lRegKeyRet = RegQueryValueEx(hkeyIEKey, lpctstrIEVersion, NULL, &dwType, (LPBYTE) tchIEVersionValue, &dwSize);
  612. if (lRegKeyRet == ERROR_SUCCESS)
  613. {
  614. try
  615. {
  616. // Got the version as a string.
  617. // Update the IE Version Property
  618. varValue = tchIEVersionValue;
  619. // Set the IEVersion Property
  620. hRes = pPCHSysInfoInstance->SetVariant(pIEVersion, varValue);
  621. if (hRes == ERROR_SUCCESS)
  622. {
  623. // Set IEVersion Failed.
  624. // Proceed anyway
  625. ErrorTrace(TRACE_ID, "SetVariant on IEVersion Field failed.");
  626. }
  627. }
  628. catch(...)
  629. {
  630. lRegKeyRet = RegCloseKey(hkeyIEKey);
  631. if(lRegKeyRet != ERROR_SUCCESS)
  632. {
  633. // Could not close the key.
  634. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  635. }
  636. throw;
  637. }
  638. } // end of if RegQueryValueEx == ERROR_SUCCESS
  639. lRegKeyRet = RegCloseKey(hkeyIEKey);
  640. if(lRegKeyRet != ERROR_SUCCESS)
  641. {
  642. // Could not close the key.
  643. ErrorTrace(TRACE_ID, "Cannot Close the Key");
  644. }
  645. } // end of if RegOpenKeyEx == ERROR_SUCCESS
  646. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  647. // MODE //
  648. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  649. // Execute the query to get Name, BootUpstate FROM Win32_ComputerSystem
  650. // Class.
  651. // pComputerSystemEnumInst contains a pointer to the instance returned.
  652. hRes = ExecWQLQuery(&pComputerSystemEnumInst, bstrComputerSystemQuery);
  653. if (SUCCEEDED(hRes))
  654. {
  655. // Query Succeeded!
  656. // Get the instance Object.
  657. if((pComputerSystemEnumInst->Next(WBEM_INFINITE, 1, &pComputerSystemObj, &ulComputerSystemRetVal)) == WBEM_S_NO_ERROR)
  658. {
  659. // Get the BootupState
  660. CopyProperty(pComputerSystemObj, lpctstrBootupState, pPCHSysInfoInstance, pMode);
  661. // Get the Manufacturer
  662. CopyProperty(pComputerSystemObj, bstrManufacturer, pPCHSysInfoInstance, pManufacturer);
  663. // Get the Model
  664. CopyProperty(pComputerSystemObj, bstrModel, pPCHSysInfoInstance, pModel);
  665. }
  666. }
  667. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  668. // PROCESSOR //
  669. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  670. // Execute the query to get "DeviceID", "Manufacturer", "Name", "CurrentClockSpeed"
  671. // from Win32_Processor Class.
  672. // Although "DeviceID" is not required to set PCH_SysInfo.Processor property
  673. // we need to query for it as its the "Key" property of the class.
  674. // pProcessorEnumInst contains a pointer to the list of instances returned.
  675. //
  676. hRes = ExecWQLQuery(&pProcessorEnumInst, bstrProcessorQuery);
  677. if (SUCCEEDED(hRes))
  678. {
  679. // Query on Win32_Processor Class Succeeded
  680. // Enumerate the instances of Win32_Processor Class
  681. // from pProcessorEnumInst.
  682. // Get the instance into pProcessorObj object.
  683. if(WBEM_S_NO_ERROR == pProcessorEnumInst->Next(WBEM_INFINITE, 1, &pProcessorObj, &ulProcessorRetVal))
  684. {
  685. //Get the Manufacturer
  686. if (FAILED(pProcessorObj->Get(bstrManufacturer, 0, &varValue, NULL, NULL)))
  687. {
  688. // Could not get the Manufacturer
  689. ErrorTrace(TRACE_ID, "GetVariant on Win32_Processor:Manufacturer Field failed.");
  690. }
  691. else
  692. {
  693. // Got the Manufacturer
  694. // varValue set to Manufacturer. Copy this to bstrResult
  695. hRes = varValue.ChangeType(VT_BSTR, NULL);
  696. if(SUCCEEDED(hRes))
  697. {
  698. bstrProcessor.Append(V_BSTR(&varValue));
  699. // Put some spaces before appending the string.
  700. bstrProcessor.Append(lpctstrSpaces);
  701. }
  702. }
  703. // Get the Name
  704. if (FAILED(pProcessorObj->Get(bstrName, 0, &varValue, NULL, NULL)))
  705. {
  706. // Could not get the Name
  707. ErrorTrace(TRACE_ID, "GetVariant on Win32_Processor:Name Field failed.");
  708. }
  709. else
  710. {
  711. // Got the Name
  712. // varValue set to Name. Append this to bstrResult
  713. hRes = varValue.ChangeType(VT_BSTR, NULL);
  714. if(SUCCEEDED(hRes))
  715. {
  716. bstrProcessor.Append(V_BSTR(&varValue));
  717. // Put some spaces before appending the string.
  718. bstrProcessor.Append(lpctstrSpaces);
  719. }
  720. }
  721. // Set the Processor Property
  722. varValue.vt = VT_BSTR;
  723. varValue.bstrVal = bstrProcessor.Detach();
  724. hRes = pPCHSysInfoInstance->SetVariant(pProcessor, varValue);
  725. if (FAILED(hRes))
  726. {
  727. // Set Processor Failed.
  728. // Proceed anyway
  729. ErrorTrace(TRACE_ID, "SetVariant on Processor Field failed.");
  730. }
  731. // Copy Property Clock speed
  732. CopyProperty(pProcessorObj, lpctstrClockSpeed, pPCHSysInfoInstance, pClockSpeed);
  733. } //end of if WBEM_S_NO_ERROR
  734. } // end of if SUCCEEDED(hRes))
  735. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  736. // RAM //
  737. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  738. // Execute the query to get "Name", "TotalPhysicalMemory"
  739. // from Win32_LogicalMemoryConfiguration Class.
  740. // Although "Name" is not required to set PCH_SysInfo.RAM property
  741. // we need to query for it as its the "Key" property of the class.
  742. // pLogicalMemConfigEnumInst contains a pointer to the list of instances returned.
  743. //
  744. hRes = ExecWQLQuery(&pLogicalMemConfigEnumInst, bstrLogicalMemConfigQuery);
  745. if (SUCCEEDED(hRes))
  746. {
  747. // Query on Win32_LogicalMemoryConfiguration Class Succeeded
  748. // Enumerate the instances of Win32_LogicalMemoryConfiguration Class
  749. // from pEnumInst.
  750. // Get the next instance into pLogicalMemConfigObj object.
  751. //
  752. if(WBEM_S_NO_ERROR == pLogicalMemConfigEnumInst->Next(WBEM_INFINITE, 1, &pLogicalMemConfigObj, &ulLogicalMemConfigRetVal))
  753. {
  754. //Get the TotalPhysicalMemory
  755. if (FAILED(pLogicalMemConfigObj->Get(lpctstrTotalPhysicalMemory, 0, &varPhysicalMem, NULL, NULL)))
  756. {
  757. // Could not get the RAM
  758. ErrorTrace(TRACE_ID, "GetVariant on Win32_LogicalMemoryConfiguration:TotalPhysicalMemory Field failed.");
  759. }
  760. else
  761. {
  762. // Got the TotalPhysicalMemory
  763. // varRAM set to TotalPhysicalMemory. Copy this to bstrResult
  764. nRam = varPhysicalMem.lVal;
  765. nRem = nRam % ONEK;
  766. nRam = nRam/ONEK;
  767. if (nRem > HALFK)
  768. {
  769. nRam++;
  770. }
  771. varRam = nRam;
  772. hRes = pPCHSysInfoInstance->SetVariant(pRAM, varRam);
  773. {
  774. // Set RAM Failed.
  775. // Proceed anyway
  776. ErrorTrace(TRACE_ID, "SetVariant on RAM Field failed.");
  777. }
  778. }
  779. }
  780. } // end of else FAILED(hRes)
  781. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  782. // SWAPFILE //
  783. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  784. // Execute the query to get "Name", "FreeSpace", "FSName"
  785. // from Win32_PageFile.
  786. // pPageFileEnumInst contains a pointer to the list of instances returned.
  787. //
  788. hRes = ExecWQLQuery(&pPageFileEnumInst, bstrPageFileQuery);
  789. if (SUCCEEDED(hRes))
  790. {
  791. // Query on Win32_PageFile Class Succeeded
  792. // Enumerate the instances of Win32_PageFile Class
  793. // from pEnumInst.
  794. // Get the next instance into pObj object.
  795. //
  796. // Initialize bstrResult to NULL;
  797. if(WBEM_S_NO_ERROR == pPageFileEnumInst->Next(WBEM_INFINITE, 1, &pPageFileObj, &ulPageFileRetVal))
  798. {
  799. //Get the Name
  800. if (FAILED(pPageFileObj->Get(bstrName, 0, &varValue, NULL, NULL)))
  801. {
  802. // Could not get the Name
  803. ErrorTrace(TRACE_ID, "GetVariant on Win32_PageFile:Name Field failed.");
  804. }
  805. else
  806. {
  807. // Got the Name.
  808. // varValue set to Name. Copy this to bstrResult
  809. hRes = varValue.ChangeType(VT_BSTR, NULL);
  810. if(SUCCEEDED(hRes))
  811. {
  812. bstrSwapFile.Append(V_BSTR(&varValue));
  813. // Put some spaces in between the two strings.
  814. bstrSwapFile.Append(lpctstrSpaces);
  815. }
  816. }
  817. // Get the FreeSpace
  818. if (FAILED(pPageFileObj->Get(bstrFreeSpace, 0, &varValue, NULL, NULL)))
  819. {
  820. // Could not get the FreeSpace
  821. ErrorTrace(TRACE_ID, "GetVariant on Win32_PageFile:FreeSpace Field failed.");
  822. }
  823. else
  824. {
  825. // Got the FreeSpace
  826. // varValue set to FreeSpace. Append this to bstrResult
  827. hRes = varValue.ChangeType(VT_BSTR, NULL);
  828. if(SUCCEEDED(hRes))
  829. {
  830. bstrSwapFile.Append(V_BSTR(&varValue));
  831. // Put some spaces in between the two strings.
  832. bstrSwapFile.Append(lpctstrSpaces);
  833. bstrSwapFile.Append(lpctstrMBFree);
  834. }
  835. }
  836. // Get the FSName
  837. if (FAILED(pPageFileObj->Get(bstrFSName, 0, &varValue, NULL, NULL)))
  838. {
  839. // Could not get the FSName
  840. ErrorTrace(TRACE_ID, "GetVariant on Win32_PageFile:FSName Field failed.");
  841. }
  842. else
  843. {
  844. // Got the FSName
  845. // varValue set to FSName. Append this to bstrResult
  846. hRes = varValue.ChangeType(VT_BSTR, NULL);
  847. if(SUCCEEDED(hRes))
  848. {
  849. bstrSwapFile.Append(V_BSTR(&varValue));
  850. }
  851. }
  852. // Set the SwapFile Property
  853. // varValue = bstrSwapFile;
  854. varValue.vt = VT_BSTR;
  855. varValue.bstrVal = bstrSwapFile.Detach();
  856. hRes = pPCHSysInfoInstance->SetVariant(pSwapFile, varValue);
  857. {
  858. // Set SwapFile Failed.
  859. // Proceed anyway
  860. ErrorTrace(TRACE_ID, "SetVariant on SwapFile Field failed.");
  861. }
  862. } //end of if WBEM_S_NO_ERROR
  863. } // end of else FAILED(hRes)
  864. // All the properties are set.
  865. if(fCommit)
  866. {
  867. hRes = pPCHSysInfoInstance->Commit();
  868. if (FAILED(hRes))
  869. {
  870. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  871. }
  872. }
  873. TraceFunctLeave();
  874. return hRes ;
  875. }