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.

152 lines
3.3 KiB

  1. #ifndef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #endif
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include "cutil.h"
  7. #define MemAlloc(a) GlobalAlloc(GMEM_FIXED, (a))
  8. #define MemFree(a) GlobalFree((a))
  9. static POSVERSIONINFO _getOSVersion(VOID)
  10. {
  11. static BOOL fFirst = TRUE;
  12. static OSVERSIONINFO os;
  13. if ( fFirst ) {
  14. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  15. if (GetVersionEx( &os ) ) {
  16. fFirst = FALSE;
  17. }
  18. }
  19. return &os;
  20. }
  21. BOOL
  22. CUtil::IsWinNT(VOID)
  23. {
  24. return (_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT);
  25. }
  26. BOOL
  27. CUtil::IsWinNT4(VOID)
  28. {
  29. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  30. (_getOSVersion()->dwMajorVersion == 4) &&
  31. (_getOSVersion()->dwMinorVersion >= 0) ) {
  32. return TRUE;
  33. }
  34. return FALSE;
  35. }
  36. BOOL
  37. CUtil::IsWinNT5(VOID)
  38. {
  39. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  40. (_getOSVersion()->dwMajorVersion == 5) &&
  41. (_getOSVersion()->dwMinorVersion >= 0)) {
  42. return TRUE;
  43. }
  44. return FALSE;
  45. }
  46. BOOL
  47. CUtil::IsWin9x(VOID)
  48. {
  49. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  50. (_getOSVersion()->dwMajorVersion >= 4)) {
  51. return TRUE;
  52. }
  53. return FALSE;
  54. }
  55. BOOL
  56. CUtil::IsWin95(VOID)
  57. {
  58. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  59. (_getOSVersion()->dwMajorVersion >= 4) &&
  60. (_getOSVersion()->dwMinorVersion < 10)) {
  61. return TRUE;
  62. }
  63. return FALSE;
  64. }
  65. BOOL
  66. CUtil::IsWin98(VOID)
  67. {
  68. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  69. (_getOSVersion()->dwMajorVersion >= 4) &&
  70. (_getOSVersion()->dwMinorVersion >= 10)) {
  71. return TRUE;
  72. }
  73. return FALSE;
  74. }
  75. BOOL
  76. CUtil::IsHydra(VOID)
  77. {
  78. #ifdef UNDER_CE
  79. return FALSE;
  80. #else //!UNDER_CE
  81. static DWORD fTested = FALSE, fHydra = FALSE;
  82. HKEY hKey;
  83. if(fTested) {
  84. return fHydra;
  85. }
  86. if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  87. TEXT("System\\CurrentControlSet\\Control\\ProductOptions"),
  88. 0,
  89. KEY_READ,
  90. &hKey)){
  91. DWORD cbData;
  92. if(ERROR_SUCCESS == RegQueryValueEx(hKey,
  93. TEXT("ProductSuite"),
  94. NULL,
  95. NULL,
  96. NULL,
  97. &cbData)){
  98. TCHAR *mszBuffer, *szCurPtr;
  99. if(NULL != (mszBuffer = (TCHAR *)MemAlloc(cbData))){
  100. RegQueryValueEx(hKey,
  101. TEXT("ProductSuite"),
  102. NULL,
  103. NULL,
  104. (unsigned char *)mszBuffer,
  105. &cbData);
  106. for(szCurPtr = mszBuffer; 0 != *szCurPtr; szCurPtr += lstrlen(szCurPtr)+1){
  107. if(0 == lstrcmpi(szCurPtr, TEXT("Terminal Server"))){
  108. fHydra = TRUE;
  109. break;
  110. }
  111. }
  112. MemFree(mszBuffer);
  113. }
  114. }
  115. RegCloseKey(hKey);
  116. }
  117. fTested = TRUE;
  118. return(fHydra);
  119. #endif //UNDER_CE
  120. }
  121. INT
  122. CUtil::GetWINDIR(LPTSTR lpstr, INT len)
  123. {
  124. #ifdef UNDER_CE
  125. static const TCHAR szWindowsDir[] = TEXT("\\Windows");
  126. _tcsncpy(lpstr, szWindowsDir, len);
  127. if(len < sizeof szWindowsDir/sizeof(TCHAR))
  128. lpstr[len-1] = TEXT('\0');
  129. return lstrlen(lpstr);
  130. #else //!UNDER_CE
  131. INT dirSize=0;
  132. if(CUtil::IsHydra()) {
  133. dirSize = ::GetEnvironmentVariable(TEXT("WINDIR"), lpstr, len);
  134. }
  135. else {
  136. dirSize = ::GetWindowsDirectory(lpstr, len);
  137. }
  138. return dirSize;
  139. #endif //UNDER_CE
  140. }