Название: Как проверить версию Windows
Отправлено: Oxana от Март 18, 2004, 13:43
Желательно с примерчиком на C++.
Название: Как проверить версию Windows
Отправлено: Злой от Март 18, 2004, 13:59
Читай справку к функции GetVersionEx и структуре OSVERSIONINFO. Вот пример из MSDN #include <windows.h> #include <stdio.h>
#define BUFSIZE 80
int main() { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx;
// Пытаемся вызвать GetVersionEx, используя структуру // OSVERSIONINFOEX. Если это не удается, используем // структуру OSVERSION.
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE; }
switch (osvi.dwPlatformId) { // Проверка на семейство Windows NT case VER_PLATFORM_WIN32_NT:
// Проверка на конкретные версии if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) printf ("Microsoft Windows Server 2003 family, ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) printf ("Microsoft Windows XP ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) printf ("Microsoft Windows 2000 ");
if ( osvi.dwMajorVersion <= 4 ) printf("Microsoft Windows NT ");
// проверка на версию Windows NT4.0SP6 или позднюю if( bOsVersionInfoEx ) { // Проверка типа рабочей станции if ( osvi.wProductType == VER_NT_WORKSTATION ) { if( osvi.dwMajorVersion == 4 ) printf ( "Workstation 4.0 " ); else if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) printf ( "Home Edition " ); else printf ( "Professional " ); } // Проверка на тип сервера else if ( osvi.wProductType == VER_NT_SERVER ) { if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) printf ( "Datacenter Edition " ); else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) printf ( "Enterprise Edition " ); else if ( osvi.wSuiteMask == VER_SUITE_BLADE ) printf ( "Web Edition " ); else printf ( "Standard Edition " ); }
else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) printf ( "Datacenter Server " ); else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) printf ( "Advanced Server " ); else printf ( "Server " ); }
else // Windows NT 4.0 { if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) printf ("Server 4.0, Enterprise Edition " ); else printf ( "Server 4.0 " ); } } } else // Проверка Windows NT 4.0 SP5 или раннюю { HKEY hKey; char szProductType[BUFSIZE]; DWORD dwBufLen=BUFSIZE; LONG lRet;
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey ); if( lRet != ERROR_SUCCESS ) return FALSE;
lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen); if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) ) return FALSE;
RegCloseKey( hKey );
if ( lstrcmpi( "WINNT", szProductType) == 0 ) printf( "Workstation " ); if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) printf( "Server " ); if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) printf( "Advanced Server " );
printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion ); }
// Показать сервис пак (если есть) и номер билда
if( osvi.dwMajorVersion == 4 && lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 ) { HKEY hKey; LONG lRet;
// Test for SP6 versus SP6a. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009", 0, KEY_QUERY_VALUE, &hKey ); if( lRet == ERROR_SUCCESS ) printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF ); else // Windows NT 4.0 prior to SP6a { printf( "%s (Build %d)\n", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); }
RegCloseKey( hKey ); } else // Windows NT 3.51 и раньше или Windows 2000 или позже { printf( "%s (Build %d)\n", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); }
break;
// Windows 95 case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { printf ("Microsoft Windows 95 "); if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) printf("OSR2 " ); }
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { printf ("Microsoft Windows 98 "); if ( osvi.szCSDVersion[1] == 'A' ) printf("SE " ); }
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { printf ("Microsoft Windows Millennium Edition\n"); } break;
case VER_PLATFORM_WIN32s:
printf ("Microsoft Win32s\n"); break; } return TRUE; }
|