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.

664 lines
15 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. (m_SysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64));
  174. }
  175. //________________________________________________________________________________
  176. //
  177. // Function: IsWin95Gold
  178. //
  179. // Synopsis: Determines if the current platform IsWin95.
  180. //
  181. // Arguments: None
  182. //
  183. // Returns: BOOL - TRUE if the current platform IsWin95
  184. //
  185. // History: quintinb Created 2/20/1998
  186. //
  187. //________________________________________________________________________________
  188. BOOL
  189. CPlatform::IsWin95Gold()
  190. {
  191. if (bad == m_ClassState)
  192. {
  193. return FALSE;
  194. }
  195. if (IsOSExact(VER_PLATFORM_WIN32_WINDOWS, 950))
  196. {
  197. return TRUE;
  198. }
  199. else
  200. {
  201. return FALSE;
  202. }
  203. }
  204. //________________________________________________________________________________
  205. //
  206. // Function: IsWin95
  207. //
  208. // Synopsis: Determines if the current platform IsWin95Gold.
  209. //
  210. // Arguments: None
  211. //
  212. // Returns: BOOL - TRUE if the current platform IsWin95Gold
  213. //
  214. // History: a-anasj Created 2/04/1998
  215. //
  216. //________________________________________________________________________________
  217. BOOL
  218. CPlatform::IsWin95()
  219. {
  220. if (bad == m_ClassState)
  221. {
  222. return FALSE;
  223. }
  224. if ( (IsOS(VER_PLATFORM_WIN32_WINDOWS, 950)) && (!IsOS(VER_PLATFORM_WIN32_WINDOWS, 1352)) )
  225. {
  226. return TRUE;
  227. }
  228. else
  229. {
  230. return FALSE;
  231. }
  232. }
  233. //________________________________________________________________________________
  234. //
  235. // Function: IsWin98
  236. //
  237. // Synopsis: Determines if the current platform IsWin98.
  238. //
  239. // Arguments: None
  240. //
  241. // Returns: BOOL - TRUE if the current platform IsWin98
  242. //
  243. // History: a-anasj Created 2/04/1998
  244. //
  245. //________________________________________________________________________________
  246. BOOL
  247. CPlatform::IsWin98()
  248. {
  249. if (bad == m_ClassState)
  250. {
  251. return FALSE;
  252. }
  253. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 1353);
  254. }
  255. //________________________________________________________________________________
  256. //
  257. // Function: IsWin98Sr
  258. //
  259. // Synopsis: Determines if the current platform is a Service Release of Win98 (not
  260. // win98 gold).
  261. //
  262. // Arguments: None
  263. //
  264. // Returns: BOOL - TRUE if the current platform is a Sr of win98
  265. //
  266. // History: quintinb created 1-8-99
  267. //
  268. //________________________________________________________________________________
  269. BOOL
  270. CPlatform::IsWin98Sr()
  271. {
  272. if (bad == m_ClassState)
  273. {
  274. return FALSE;
  275. }
  276. //
  277. // Win98 gold had 1998 for the build number
  278. //
  279. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 1998);
  280. }
  281. //________________________________________________________________________________
  282. //
  283. // Function: IsWin98Gold
  284. //
  285. // Synopsis: Determines if the current platform is Win98 Gold (build Num 1998)
  286. //
  287. // Arguments: None
  288. //
  289. // Returns: BOOL - TRUE if the current platform is Gold win98
  290. //
  291. // History: quintinb created 1-8-99
  292. //
  293. //________________________________________________________________________________
  294. BOOL
  295. CPlatform::IsWin98Gold()
  296. {
  297. if (bad == m_ClassState)
  298. {
  299. return FALSE;
  300. }
  301. if ((IsOS(VER_PLATFORM_WIN32_WINDOWS, 1353)) && (!IsOS(VER_PLATFORM_WIN32_WINDOWS, 1998)))
  302. {
  303. return TRUE;
  304. }
  305. else
  306. {
  307. return FALSE;
  308. }
  309. }
  310. //________________________________________________________________________________
  311. //
  312. // Function: IsWin9x
  313. //
  314. // Synopsis: Determines if the current platform IsWin9x.
  315. //
  316. // Arguments: None
  317. //
  318. // Returns: BOOL - TRUE if the current platform IsWin9x
  319. //
  320. // History: a-anasj Created 2/04/1998
  321. //
  322. //________________________________________________________________________________
  323. BOOL
  324. CPlatform::IsWin9x()
  325. {
  326. if (bad == m_ClassState)
  327. {
  328. return FALSE;
  329. }
  330. return IsOS(VER_PLATFORM_WIN32_WINDOWS, 950-1);
  331. }
  332. //________________________________________________________________________________
  333. //
  334. // Function: IsNT31
  335. //
  336. // Synopsis: Determines if the current platform IsNT31.
  337. //
  338. // Arguments: None
  339. //
  340. // Returns: BOOL - TRUE if the current platform IsNT31
  341. //
  342. // History: a-anasj Created 2/04/1998
  343. //
  344. //________________________________________________________________________________
  345. BOOL
  346. CPlatform::IsNT31()
  347. {
  348. if (bad == m_ClassState)
  349. {
  350. return false;
  351. }
  352. if ( (IsOS(VER_PLATFORM_WIN32_NT , 0)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1057)) )
  353. {
  354. return TRUE;
  355. }
  356. else
  357. {
  358. return FALSE;
  359. }
  360. }
  361. //________________________________________________________________________________
  362. //
  363. // Function: IsNT351
  364. //
  365. // Synopsis: Determines if the current platform IsNT351.
  366. //
  367. // Arguments: None
  368. //
  369. // Returns: BOOL - TRUE if the current platform IsNT351
  370. //
  371. // History: a-anasj Created 2/04/1998
  372. //
  373. //________________________________________________________________________________
  374. BOOL
  375. CPlatform::IsNT351()
  376. {
  377. if (bad == m_ClassState)
  378. {
  379. return false;
  380. }
  381. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1056)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1382)) )
  382. {
  383. return TRUE;
  384. }
  385. else
  386. {
  387. return FALSE;
  388. }
  389. }
  390. //________________________________________________________________________________
  391. //
  392. // Function: IsNT4
  393. //
  394. // Synopsis: Determines if the current platform IsNT4.
  395. //
  396. // Arguments: None
  397. //
  398. // Returns: BOOL - TRUE if the current platform IsNT4
  399. //
  400. // History: a-anasj Created 2/04/1998
  401. //
  402. //________________________________________________________________________________
  403. BOOL
  404. CPlatform::IsNT4()
  405. {
  406. if (bad == m_ClassState)
  407. {
  408. return FALSE;
  409. }
  410. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1380)) && (!IsOS(VER_PLATFORM_WIN32_NT , 1500)) ) //1500 not sure
  411. {
  412. return TRUE;
  413. }
  414. else
  415. {
  416. return FALSE;
  417. }
  418. }
  419. //________________________________________________________________________________
  420. //
  421. // Function: IsAtLeastNT5
  422. //
  423. // Synopsis: Determines if the current platform at least NT5.
  424. //
  425. // Arguments: None
  426. //
  427. // Returns: BOOL - TRUE if the current platform is NT5 or newer
  428. //
  429. // History: a-anasj Created 2/04/1998
  430. //
  431. //________________________________________________________________________________
  432. BOOL
  433. CPlatform::IsAtLeastNT5()
  434. {
  435. if (bad == m_ClassState)
  436. {
  437. return FALSE;
  438. }
  439. return IsOS(VER_PLATFORM_WIN32_NT, 1500);
  440. }
  441. //________________________________________________________________________________
  442. //
  443. // Function: IsAtLeastNT51
  444. //
  445. // Synopsis: Determines if the current platform at least NT51.
  446. //
  447. // Arguments: None
  448. //
  449. // Returns: BOOL - TRUE if the current platform is NT5 or newer
  450. //
  451. // History: quintinb Created 02/09/2001
  452. //
  453. //________________________________________________________________________________
  454. BOOL
  455. CPlatform::IsAtLeastNT51()
  456. {
  457. if (bad == m_ClassState)
  458. {
  459. return FALSE;
  460. }
  461. return IsOS(VER_PLATFORM_WIN32_NT, 2200);
  462. }
  463. //________________________________________________________________________________
  464. //
  465. // Function: IsNT5
  466. //
  467. // Synopsis: Determines if the current platform is NT5.
  468. //
  469. // Arguments: None
  470. //
  471. // Returns: BOOL - TRUE if the current platform is NT5
  472. //
  473. // History: a-anasj Created 2/04/1998
  474. //
  475. //________________________________________________________________________________
  476. BOOL
  477. CPlatform::IsNT5()
  478. {
  479. if (bad == m_ClassState)
  480. {
  481. return FALSE;
  482. }
  483. if ( (IsOS(VER_PLATFORM_WIN32_NT , 1500)) && (!IsOS(VER_PLATFORM_WIN32_NT , 2195)))
  484. {
  485. return TRUE;
  486. }
  487. else
  488. {
  489. return FALSE;
  490. }
  491. }
  492. //________________________________________________________________________________
  493. //
  494. // Function: IsNT51
  495. //
  496. // Synopsis: Determines if the current platform at least NT51.
  497. //
  498. // Arguments: None
  499. //
  500. // Returns: BOOL - TRUE if the current platform is NT51
  501. //
  502. // History: quintinb Created 02/09/2001
  503. //
  504. //________________________________________________________________________________
  505. BOOL
  506. CPlatform::IsNT51()
  507. {
  508. if (bad == m_ClassState)
  509. {
  510. return FALSE;
  511. }
  512. if ((IsOS(VER_PLATFORM_WIN32_NT , 2195)) && (!IsOS(VER_PLATFORM_WIN32_NT , 2600))) // ISSUE quintinb 3/22/01: Update this if we need it.
  513. {
  514. return TRUE;
  515. }
  516. else
  517. {
  518. return FALSE;
  519. }
  520. }
  521. //________________________________________________________________________________
  522. //
  523. // Function: IsNT
  524. //
  525. // Synopsis: Determines if the current platform IsNT.
  526. //
  527. // Arguments: None
  528. //
  529. // Returns: BOOL - TRUE if the current platform IsNT
  530. //
  531. // History: quintinb Created 9/22/1998
  532. //
  533. //________________________________________________________________________________
  534. BOOL
  535. CPlatform::IsNT()
  536. {
  537. if (bad == m_ClassState)
  538. {
  539. return FALSE;
  540. }
  541. return IsOS(VER_PLATFORM_WIN32_NT, 0);
  542. }
  543. //________________________________________________________________________________
  544. //
  545. // Function: IsNTSrv
  546. //
  547. // Synopsis: Determines if the current platform IsNT.
  548. //
  549. // Arguments: None
  550. //
  551. // Returns: BOOL - TRUE if the current platform IsNT
  552. //
  553. // History: quintinb Created 9/22/1998
  554. //
  555. //________________________________________________________________________________
  556. BOOL CPlatform::IsNTSrv()
  557. {
  558. HKEY hKey;
  559. TCHAR szTemp[MAX_PATH+1];
  560. BOOL bReturn = FALSE;
  561. if ((good == m_ClassState) && (IsOS(VER_PLATFORM_WIN32_NT, 0)))
  562. {
  563. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, c_pszSrvOrWksPath, &hKey))
  564. {
  565. DWORD dwSize = MAX_PATH;
  566. DWORD dwType = REG_SZ;
  567. if (ERROR_SUCCESS == RegQueryValueEx(hKey, c_pszProductType, NULL, &dwType,
  568. (LPBYTE)szTemp, &dwSize))
  569. {
  570. bReturn = ((0 == lstrcmpi(szTemp, c_pszSrvString)) ||
  571. (0 == lstrcmpi(szTemp, c_pszEntString)));
  572. }
  573. RegCloseKey(hKey);
  574. }
  575. }
  576. return bReturn;
  577. }
  578. BOOL CPlatform::IsNTWks()
  579. {
  580. HKEY hKey;
  581. TCHAR szTemp[MAX_PATH+1];
  582. BOOL bReturn = FALSE;
  583. if ((good == m_ClassState) && (IsOS(VER_PLATFORM_WIN32_NT, 0)))
  584. {
  585. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, c_pszSrvOrWksPath, &hKey))
  586. {
  587. DWORD dwSize = MAX_PATH;
  588. DWORD dwType = REG_SZ;
  589. if (ERROR_SUCCESS == RegQueryValueEx(hKey, c_pszProductType, NULL, &dwType,
  590. (LPBYTE)szTemp, &dwSize))
  591. {
  592. bReturn = (0 == lstrcmpi(szTemp, c_pszWksString));
  593. }
  594. RegCloseKey(hKey);
  595. }
  596. }
  597. return bReturn;
  598. }