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.

666 lines
14 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmplat.cpp
  4. //
  5. // Module: CMSETUP.LIB
  6. //
  7. // Synopsis: Implementation of CPlatform class
  8. // use it to query the system for all kinds of platform info
  9. // OSVersion, machine architecture, etc....
  10. //
  11. // Copyright (c) 1998-1999 Microsoft Corporation
  12. //
  13. // Author: quintinb Created Header 08/19/99
  14. //
  15. //+----------------------------------------------------------------------------
  16. #include "cmplat.h"
  17. //
  18. // Constants
  19. //
  20. const TCHAR* const c_pszSrvOrWksPath = TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions");
  21. const TCHAR* const c_pszProductType = TEXT("ProductType");
  22. const TCHAR* const c_pszSrvString = TEXT("ServerNT");
  23. const TCHAR* const c_pszEntString = TEXT("LanManNT");
  24. const TCHAR* const c_pszWksString = TEXT("WinNT");
  25. //________________________________________________________________________________
  26. //
  27. // Function: CPlatform constructor
  28. //
  29. // Synopsis: .initializes the class, all the functions are ready to be used
  30. //
  31. // Arguments: None
  32. //
  33. // Returns: NONE
  34. //
  35. // History: a-anasj Created 2/04/1998
  36. //
  37. //________________________________________________________________________________
  38. CPlatform::CPlatform()
  39. {
  40. ZeroMemory(&m_SysInfo, sizeof(m_SysInfo));
  41. GetSystemInfo(&m_SysInfo); // Does not fail!
  42. m_OSVer.dwOSVersionInfoSize = sizeof(m_OSVer);
  43. if (!GetVersionEx(&m_OSVer))
  44. {
  45. m_ClassState = bad; //Something went wrong
  46. }
  47. else
  48. {
  49. m_ClassState = good;
  50. }
  51. }
  52. //________________________________________________________________________________
  53. //
  54. // Function: IsOS
  55. //
  56. // Synopsis:
  57. //
  58. // Arguments: DWORD OS, DWORD buildNum
  59. //
  60. // Returns: BOOL - TRUE means running on OS specified
  61. //
  62. // History: Created Header 1/30/98
  63. //
  64. //________________________________________________________________________________
  65. BOOL CPlatform::IsOS(DWORD OS, DWORD buildNum)
  66. {
  67. if (m_OSVer.dwPlatformId != OS)
  68. {
  69. return FALSE;
  70. }
  71. if ( (m_OSVer.dwBuildNumber & 0xffff) > buildNum) //Check for higher than developer release
  72. {
  73. return TRUE;
  74. }
  75. else
  76. {
  77. return FALSE;
  78. }
  79. }
  80. //________________________________________________________________________________
  81. //
  82. // Function: IsOSExact
  83. //
  84. // Synopsis:
  85. //
  86. // Arguments: DWORD OS, DWORD buildNum
  87. //
  88. // Returns: BOOL - TRUE means running on OS specified
  89. //
  90. // History: Created Header 1/30/98
  91. //
  92. //________________________________________________________________________________
  93. BOOL CPlatform::IsOSExact(DWORD OS, DWORD buildNum)
  94. {
  95. if (m_OSVer.dwPlatformId != OS)
  96. {
  97. return FALSE;
  98. }
  99. if ((m_OSVer.dwBuildNumber & 0xffff) == buildNum) //Check for exact match
  100. {
  101. return TRUE;
  102. }
  103. else
  104. {
  105. return FALSE;
  106. }
  107. }
  108. //________________________________________________________________________________
  109. //
  110. // Function: IsX86
  111. //
  112. // Synopsis: Determines if the current platform IsX86.
  113. //
  114. // Arguments: None
  115. //
  116. // Returns: BOOL - TRUE if the current platform IsX86
  117. //
  118. // History: a-anasj Created 2/04/1998
  119. //
  120. //________________________________________________________________________________
  121. BOOL
  122. CPlatform::IsX86()
  123. {
  124. if (bad == m_ClassState)
  125. {
  126. return FALSE;
  127. }
  128. return (m_SysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL);
  129. }
  130. //________________________________________________________________________________
  131. //
  132. // Function: IsAlpha
  133. //
  134. // Synopsis: Determines if the current platform IsAlpha.
  135. //
  136. // Arguments: None
  137. //
  138. // Returns: BOOL - TRUE if the current platform IsAlpha
  139. //
  140. // History: a-anasj Created 2/04/1998
  141. //
  142. //________________________________________________________________________________
  143. BOOL
  144. CPlatform::IsAlpha()
  145. {
  146. if (bad == m_ClassState)
  147. {
  148. return FALSE;
  149. }
  150. return (m_SysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA);
  151. }
  152. //________________________________________________________________________________
  153. //
  154. // Function: IsIA64
  155. //
  156. // Synopsis: Determines if the current platform is an IA64 machine.
  157. //
  158. // Arguments: None
  159. //
  160. // Returns: BOOL - TRUE if the current platform is an itanium.
  161. //
  162. // History: quintinb Created 07/20/2000
  163. //
  164. //________________________________________________________________________________
  165. BOOL
  166. CPlatform::IsIA64()
  167. {
  168. if (bad == m_ClassState)
  169. {
  170. return FALSE;
  171. }
  172. return (m_SysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64);
  173. }
  174. //________________________________________________________________________________
  175. //
  176. // Function: IsWin95Gold
  177. //
  178. // Synopsis: Determines if the current platform IsWin95.
  179. //
  180. // Arguments: None
  181. //
  182. // Returns: BOOL - TRUE if the current platform IsWin95
  183. //
  184. // History: quintinb Created 2/20/1998
  185. //
  186. //________________________________________________________________________________
  187. BOOL
  188. CPlatform::IsWin95Gold()
  189. {
  190. if (bad == m_ClassState)
  191. {
  192. return FALSE;
  193. }
  194. if (IsOSExact(VER_PLATFORM_WIN32_WINDOWS, 950))
  195. {
  196. return TRUE;
  197. }
  198. else
  199. {
  200. return FALSE;
  201. }
  202. }
  203. //________________________________________________________________________________
  204. //
  205. // Function: IsWin95
  206. //
  207. // Synopsis: Determines if the current platform IsWin95Gold.
  208. //
  209. // Arguments: None
  210. //
  211. // Returns: BOOL - TRUE if the current platform IsWin95Gold
  212. //
  213. // History: a-anasj Created 2/04/1998
  214. //
  215. //________________________________________________________________________________
  216. BOOL
  217. CPlatform::IsWin95()
  218. {
  219. if (bad == m_ClassState)
  220. {
  221. return FALSE;
  222. }
  223. if ( (IsOS(VER_PLATFORM_WIN32_WINDOWS, 950)) && (!IsOS(VER_PLATFORM_WIN32_WINDOWS, 1352)) )
  224. {
  225. return TRUE;
  226. }
  227. else
  228. {
  229. return FALSE;
  230. }
  231. }
  232. //________________________________________________________________________________
  233. //
  234. // Function: IsWin98
  235. //
  236. // Synopsis: Determines if the current platform IsWin98.
  237. //
  238. // Arguments: None
  239. //
  240. // Returns: BOOL - TRUE if the current platform IsWin98
  241. //
  242. // History: a-anasj Created 2/04/1998
  243. //
  244. //________________________________________________________________________________
  245. BOOL
  246. CPlatform::IsWin98()
  247. {
  248. if (bad == m_ClassState)
  249. {
  250. return FALSE;
  251. }
  252. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 1353);
  253. }
  254. //________________________________________________________________________________
  255. //
  256. // Function: IsWin98Sr
  257. //
  258. // Synopsis: Determines if the current platform is a Service Release of Win98 (not
  259. // win98 gold).
  260. //
  261. // Arguments: None
  262. //
  263. // Returns: BOOL - TRUE if the current platform is a Sr of win98
  264. //
  265. // History: quintinb created 1-8-99
  266. //
  267. //________________________________________________________________________________
  268. BOOL
  269. CPlatform::IsWin98Sr()
  270. {
  271. if (bad == m_ClassState)
  272. {
  273. return FALSE;
  274. }
  275. //
  276. // Win98 gold had 1998 for the build number
  277. //
  278. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 1998);
  279. }
  280. //________________________________________________________________________________
  281. //
  282. // Function: IsWin98Gold
  283. //
  284. // Synopsis: Determines if the current platform is Win98 Gold (build Num 1998)
  285. //
  286. // Arguments: None
  287. //
  288. // Returns: BOOL - TRUE if the current platform is Gold win98
  289. //
  290. // History: quintinb created 1-8-99
  291. //
  292. //________________________________________________________________________________
  293. BOOL
  294. CPlatform::IsWin98Gold()
  295. {
  296. if (bad == m_ClassState)
  297. {
  298. return FALSE;
  299. }
  300. if ((IsOS(VER_PLATFORM_WIN32_WINDOWS, 1353)) && (!IsOS(VER_PLATFORM_WIN32_WINDOWS, 1998)))
  301. {
  302. return TRUE;
  303. }
  304. else
  305. {
  306. return FALSE;
  307. }
  308. }
  309. //________________________________________________________________________________
  310. //
  311. // Function: IsWin9x
  312. //
  313. // Synopsis: Determines if the current platform IsWin9x.
  314. //
  315. // Arguments: None
  316. //
  317. // Returns: BOOL - TRUE if the current platform IsWin9x
  318. //
  319. // History: a-anasj Created 2/04/1998
  320. //
  321. //________________________________________________________________________________
  322. BOOL
  323. CPlatform::IsWin9x()
  324. {
  325. if (bad == m_ClassState)
  326. {
  327. return FALSE;
  328. }
  329. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 950-1);
  330. }
  331. //________________________________________________________________________________
  332. //
  333. // Function: IsNT31
  334. //
  335. // Synopsis: Determines if the current platform IsNT31.
  336. //
  337. // Arguments: None
  338. //
  339. // Returns: BOOL - TRUE if the current platform IsNT31
  340. //
  341. // History: a-anasj Created 2/04/1998
  342. //
  343. //________________________________________________________________________________
  344. BOOL
  345. CPlatform::IsNT31()
  346. {
  347. if (bad == m_ClassState)
  348. {
  349. return false;
  350. }
  351. if ( (IsOS(VER_PLATFORM_WIN32_NT , 0)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1057)) )
  352. {
  353. return TRUE;
  354. }
  355. else
  356. {
  357. return FALSE;
  358. }
  359. }
  360. //________________________________________________________________________________
  361. //
  362. // Function: IsNT351
  363. //
  364. // Synopsis: Determines if the current platform IsNT351.
  365. //
  366. // Arguments: None
  367. //
  368. // Returns: BOOL - TRUE if the current platform IsNT351
  369. //
  370. // History: a-anasj Created 2/04/1998
  371. //
  372. //________________________________________________________________________________
  373. BOOL
  374. CPlatform::IsNT351()
  375. {
  376. if (bad == m_ClassState)
  377. {
  378. return false;
  379. }
  380. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1056)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1382)) )
  381. {
  382. return TRUE;
  383. }
  384. else
  385. {
  386. return FALSE;
  387. }
  388. }
  389. //________________________________________________________________________________
  390. //
  391. // Function: IsNT4
  392. //
  393. // Synopsis: Determines if the current platform IsNT4.
  394. //
  395. // Arguments: None
  396. //
  397. // Returns: BOOL - TRUE if the current platform IsNT4
  398. //
  399. // History: a-anasj Created 2/04/1998
  400. //
  401. //________________________________________________________________________________
  402. BOOL
  403. CPlatform::IsNT4()
  404. {
  405. if (bad == m_ClassState)
  406. {
  407. return FALSE;
  408. }
  409. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1380)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1500)) ) //1500 not sure
  410. {
  411. return TRUE;
  412. }
  413. else
  414. {
  415. return FALSE;
  416. }
  417. }
  418. //________________________________________________________________________________
  419. //
  420. // Function: IsAtLeastNT5
  421. //
  422. // Synopsis: Determines if the current platform at least NT5.
  423. //
  424. // Arguments: None
  425. //
  426. // Returns: BOOL - TRUE if the current platform is NT5 or newer
  427. //
  428. // History: a-anasj Created 2/04/1998
  429. //
  430. //________________________________________________________________________________
  431. BOOL
  432. CPlatform::IsAtLeastNT5()
  433. {
  434. if (bad == m_ClassState)
  435. {
  436. return FALSE;
  437. }
  438. return IsOS(VER_PLATFORM_WIN32_NT, 1500);
  439. }
  440. //________________________________________________________________________________
  441. //
  442. // Function: IsAtLeastNT51
  443. //
  444. // Synopsis: Determines if the current platform at least NT51.
  445. //
  446. // Arguments: None
  447. //
  448. // Returns: BOOL - TRUE if the current platform is NT5 or newer
  449. //
  450. // History: quintinb Created 02/09/2001
  451. //
  452. //________________________________________________________________________________
  453. BOOL
  454. CPlatform::IsAtLeastNT51()
  455. {
  456. if (bad == m_ClassState)
  457. {
  458. return FALSE;
  459. }
  460. return IsOS(VER_PLATFORM_WIN32_NT, 2200);
  461. }
  462. //________________________________________________________________________________
  463. //
  464. // Function: IsNT5
  465. //
  466. // Synopsis: Determines if the current platform is NT5.
  467. //
  468. // Arguments: None
  469. //
  470. // Returns: BOOL - TRUE if the current platform is NT5
  471. //
  472. // History: a-anasj Created 2/04/1998
  473. //
  474. //________________________________________________________________________________
  475. BOOL
  476. CPlatform::IsNT5()
  477. {
  478. if (bad == m_ClassState)
  479. {
  480. return FALSE;
  481. }
  482. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1500)) && (!IsOS(VER_PLATFORM_WIN32_NT , 2195)))
  483. {
  484. return TRUE;
  485. }
  486. else
  487. {
  488. return FALSE;
  489. }
  490. }
  491. //________________________________________________________________________________
  492. //
  493. // Function: IsNT51
  494. //
  495. // Synopsis: Determines if the current platform at least NT51.
  496. //
  497. // Arguments: None
  498. //
  499. // Returns: BOOL - TRUE if the current platform is NT51
  500. //
  501. // History: quintinb Created 02/09/2001
  502. //
  503. //________________________________________________________________________________
  504. BOOL
  505. CPlatform::IsNT51()
  506. {
  507. if (bad == m_ClassState)
  508. {
  509. return FALSE;
  510. }
  511. if ((IsOS(VER_PLATFORM_WIN32_NT , 2195)) && (!IsOS(VER_PLATFORM_WIN32_NT , 2600))) // ISSUE quintinb 3/22/01: Update this if we need it.
  512. {
  513. return TRUE;
  514. }
  515. else
  516. {
  517. return FALSE;
  518. }
  519. }
  520. //________________________________________________________________________________
  521. //
  522. // Function: IsNT
  523. //
  524. // Synopsis: Determines if the current platform IsNT.
  525. //
  526. // Arguments: None
  527. //
  528. // Returns: BOOL - TRUE if the current platform IsNT
  529. //
  530. // History: quintinb Created 9/22/1998
  531. //
  532. //________________________________________________________________________________
  533. BOOL
  534. CPlatform::IsNT()
  535. {
  536. if (bad == m_ClassState)
  537. {
  538. return FALSE;
  539. }
  540. return IsOS(VER_PLATFORM_WIN32_NT, 0);
  541. }
  542. //________________________________________________________________________________
  543. //
  544. // Function: IsNTSrv
  545. //
  546. // Synopsis: Determines if the current platform IsNT.
  547. //
  548. // Arguments: None
  549. //
  550. // Returns: BOOL - TRUE if the current platform IsNT
  551. //
  552. // History: quintinb Created 9/22/1998
  553. //
  554. //________________________________________________________________________________
  555. BOOL CPlatform::IsNTSrv()
  556. {
  557. HKEY hKey;
  558. TCHAR szTemp[MAX_PATH+1];
  559. BOOL bReturn = FALSE;
  560. if ((good == m_ClassState) && (IsOS(VER_PLATFORM_WIN32_NT, 0)))
  561. {
  562. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, c_pszSrvOrWksPath, &hKey))
  563. {
  564. DWORD dwSize = MAX_PATH;
  565. DWORD dwType = REG_SZ;
  566. if (ERROR_SUCCESS == RegQueryValueEx(hKey, c_pszProductType, NULL, &dwType,
  567. (LPBYTE)szTemp, &dwSize))
  568. {
  569. bReturn = ((0 == lstrcmpi(szTemp, c_pszSrvString)) ||
  570. (0 == lstrcmpi(szTemp, c_pszEntString)));
  571. }
  572. RegCloseKey(hKey);
  573. }
  574. }
  575. return bReturn;
  576. }
  577. BOOL CPlatform::IsNTWks()
  578. {
  579. HKEY hKey;
  580. TCHAR szTemp[MAX_PATH+1];
  581. BOOL bReturn = FALSE;
  582. if ((good == m_ClassState) && (IsOS(VER_PLATFORM_WIN32_NT, 0)))
  583. {
  584. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, c_pszSrvOrWksPath, &hKey))
  585. {
  586. DWORD dwSize = MAX_PATH;
  587. DWORD dwType = REG_SZ;
  588. if (ERROR_SUCCESS == RegQueryValueEx(hKey, c_pszProductType, NULL, &dwType,
  589. (LPBYTE)szTemp, &dwSize))
  590. {
  591. bReturn = (0 == lstrcmpi(szTemp, c_pszWksString));
  592. }
  593. RegCloseKey(hKey);
  594. }
  595. }
  596. return bReturn;
  597. }