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.

150 lines
3.9 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. return TRUE;
  32. }
  33. return FALSE;
  34. }
  35. BOOL
  36. CUtil::IsWinNT5(VOID)
  37. {
  38. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  39. (_getOSVersion()->dwMajorVersion == 5)) {
  40. return TRUE;
  41. }
  42. return FALSE;
  43. }
  44. BOOL
  45. CUtil::IsWin9x(VOID)
  46. {
  47. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  48. (_getOSVersion()->dwMajorVersion >= 4)) {
  49. return TRUE;
  50. }
  51. return FALSE;
  52. }
  53. BOOL
  54. CUtil::IsWin95(VOID)
  55. {
  56. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  57. (_getOSVersion()->dwMajorVersion >= 4) &&
  58. (_getOSVersion()->dwMinorVersion < 10)) {
  59. return TRUE;
  60. }
  61. return FALSE;
  62. }
  63. BOOL
  64. CUtil::IsWin98(VOID)
  65. {
  66. if((_getOSVersion()->dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  67. (_getOSVersion()->dwMajorVersion >= 4) &&
  68. (_getOSVersion()->dwMinorVersion >= 10)) {
  69. return TRUE;
  70. }
  71. return FALSE;
  72. }
  73. BOOL
  74. CUtil::IsHydra(VOID)
  75. {
  76. #ifdef UNDER_CE
  77. return FALSE;
  78. #else //!UNDER_CE
  79. static DWORD fTested = FALSE, fHydra = FALSE;
  80. HKEY hKey;
  81. if(fTested) {
  82. return fHydra;
  83. }
  84. if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  85. TEXT("System\\CurrentControlSet\\Control\\ProductOptions"),
  86. 0,
  87. KEY_READ,
  88. &hKey)){
  89. DWORD cbData = 0;
  90. if(ERROR_SUCCESS == RegQueryValueEx(hKey,
  91. TEXT("ProductSuite"),
  92. NULL,
  93. NULL,
  94. NULL,
  95. &cbData)){
  96. TCHAR *mszBuffer, *szCurPtr;
  97. if(NULL != (mszBuffer = (TCHAR *)MemAlloc(cbData))){
  98. RegQueryValueEx(hKey,
  99. TEXT("ProductSuite"),
  100. NULL,
  101. NULL,
  102. (unsigned char *)mszBuffer,
  103. &cbData);
  104. for(szCurPtr = mszBuffer; 0 != *szCurPtr; szCurPtr += lstrlen(szCurPtr)+1){
  105. if(0 == lstrcmpi(szCurPtr, TEXT("Terminal Server"))){
  106. fHydra = TRUE;
  107. break;
  108. }
  109. }
  110. MemFree(mszBuffer);
  111. }
  112. }
  113. RegCloseKey(hKey);
  114. }
  115. fTested = TRUE;
  116. return(fHydra);
  117. #endif //UNDER_CE
  118. }
  119. INT
  120. CUtil::GetWINDIR(LPTSTR lpstr, INT len)
  121. {
  122. #ifdef UNDER_CE
  123. static const TCHAR szWindowsDir[] = TEXT("\\Windows");
  124. _tcsncpy(lpstr, szWindowsDir, len);
  125. if(len < sizeof szWindowsDir/sizeof(TCHAR))
  126. lpstr[len-1] = TEXT('\0');
  127. return lstrlen(lpstr);
  128. #else //!UNDER_CE
  129. INT dirSize=0;
  130. if(CUtil::IsHydra()) {
  131. dirSize = ::GetEnvironmentVariable(TEXT("WINDIR"), lpstr, len);
  132. }
  133. else {
  134. dirSize = ::GetWindowsDirectory(lpstr, len);
  135. }
  136. return dirSize;
  137. #endif //UNDER_CE
  138. }