권과장이 만들어 둔 함수.
microsoft에서 제공 해 준대로 쓰려면 헷갈리고 불편해서.. 사용하기 편하도록 만들어 둔 거당..
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 작성 : 2008-09-11 CROWBACK // 수정 : 2008-09-17 CROWBACK // 64비트 Windows 2008 버전을 잘못 읽어오던것 수정됨. // // 윈도우의 버전 정보를 읽어오는 클래스. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class CWindowsVersion { public: typedef enum { eWindows32, eWindows95, eWindows98, eWindowsME, eWindowsNT, eWindows2000, eWindowsXP, eWindows2003, eWindowsVista, eWindows2008, eWindowsUnknown } eOsType; typedef enum { Bit32, Bit64, ArchUnknown } eOsArch; public: CWindowsVersion(); void CheckVersion(); const char* GetTypeString(eOsType type); const char* GetArchString(eOsArch arch); public: eOsType m_Type; eOsArch m_Arch; char m_SubType[512]; UINT m_Build; char m_ServicePack[512]; }; typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); CWindowsVersion::CWindowsVersion() { m_Type = eWindowsUnknown; m_Arch = Bit32; m_Build = 0; m_SubType[0] = 0; m_ServicePack[0]= 0; CheckVersion(); } const char* OsTypeStriung[] = { "Windows Win32", "Windows 95", "Windows 98", "Windows ME", "Windows NT", "Windows 2000", "Windows XP", "Windows 2003", "Windows Vista", "Windows 2008", "Windows Unknown" }; const char* OsArchStriung[] = { "32bit", "64bit", "Unknown" }; const char* CWindowsVersion::GetTypeString(eOsType type) { if( type < eWindows32 && eWindows2008 < type) return OsTypeStriung[eWindowsUnknown]; return OsTypeStriung[type]; } const char* CWindowsVersion::GetArchString(eOsArch arch) { if( arch < Bit32 && Bit64 < arch) return OsTypeStriung[ArchUnknown]; return OsArchStriung[arch]; } void CWindowsVersion::CheckVersion() { OSVERSIONINFOEX osvi; SYSTEM_INFO si; PGNSI pGNSI; BOOL bOsVersionInfoEx; ZeroMemory(&si, sizeof(SYSTEM_INFO)); ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); // Try calling GetVersionEx using the OSVERSIONINFOEX structure. // If that fails, try using the OSVERSIONINFO structure. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi); if( !bOsVersionInfoEx ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return; } // Call GetNativeSystemInfo if supported // or GetSystemInfo otherwise. pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); if(NULL != pGNSI) pGNSI(&si); else GetSystemInfo(&si); switch (osvi.dwPlatformId) { // Test for the Windows NT product family. case VER_PLATFORM_WIN32_NT: { // Test for the specific product. if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) { if( osvi.wProductType == VER_NT_WORKSTATION ) m_Type = eWindowsVista; else m_Type = eWindows2008; } if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) { if( GetSystemMetrics(SM_SERVERR2) ) m_Type = eWindows2003, strcat(m_SubType, "R2 "); else if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) m_Type = eWindowsXP, m_Arch = Bit64; else m_Type = eWindows2003; } if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) m_Type = eWindowsXP; if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) m_Type = eWindows2000; if ( osvi.dwMajorVersion <= 4 ) m_Type = eWindowsNT; // Test for specific product on Windows NT 4.0 SP6 and later. if( bOsVersionInfoEx ) { // Test for the workstation type. if ( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64) { if( osvi.dwMajorVersion == 4 ) strcat(m_SubType, "Workstation 4.0 "); else if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) strcat(m_SubType, "Home Edition "); else strcat(m_SubType, "Professional "); } // Test for the server type. else if ( osvi.wProductType == VER_NT_SERVER || osvi.wProductType == VER_NT_DOMAIN_CONTROLLER ) { if((osvi.dwMajorVersion==5 && osvi.dwMinorVersion>=2) || osvi.dwMajorVersion >= 6) { if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 ) { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) strcat(m_SubType, "Datacenter Edition "), m_Arch = Bit64; else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) strcat(m_SubType, "Enterprise Edition "), m_Arch = Bit64; } else if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ) { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) strcat(m_SubType, "Datacenter Edition "), m_Arch = Bit64; else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) strcat(m_SubType, "Enterprise Edition "), m_Arch = Bit64; else strcat(m_SubType, "Standard Edition "), m_Arch = Bit64; } else { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) strcat(m_SubType, "Datacenter Edition "); else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) strcat(m_SubType, "Enterprise Edition "); else if ( osvi.wSuiteMask & VER_SUITE_BLADE ) strcat(m_SubType, "Web Edition "); else strcat(m_SubType, "Standard Edition "); } } else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0) { if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) strcat(m_SubType, "Datacenter Server "); else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) strcat(m_SubType, "Advanced Server "); else strcat(m_SubType, "Server "); } else // Windows NT 4.0 { if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) strcat(m_SubType, "Server 4.0, Enterprise Edition "); else strcat(m_SubType, "Server 4.0 "); } } } // Display service pack (if any) and build number. if( osvi.dwMajorVersion == 4 && lstrcmpi( osvi.szCSDVersion, TEXT("Service Pack 6") ) == 0 ) { HKEY hKey; LONG lRet; // Test for SP6 versus SP6a. lRet = WOW::RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey ); if( lRet == ERROR_SUCCESS ) strcat(m_ServicePack, "Service Pack 6a"), m_Build = osvi.dwBuildNumber & 0xFFFF; else // Windows NT 4.0 prior to SP6a strcat(m_ServicePack, osvi.szCSDVersion), m_Build = osvi.dwBuildNumber & 0xFFFF; WOW::RegCloseKey( hKey ); } else // not Windows NT 4.0 strcat(m_ServicePack, osvi.szCSDVersion), m_Build = osvi.dwBuildNumber & 0xFFFF; break; } // Test for the Windows Me/98/95. case VER_PLATFORM_WIN32_WINDOWS: { if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { m_Type = eWindows95; if (osvi.szCSDVersion[1]=='C' || osvi.szCSDVersion[1]=='B') strcat(m_SubType, "OSR2 "); } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { m_Type = eWindows98; if ( osvi.szCSDVersion[1]=='A' || osvi.szCSDVersion[1]=='B') strcat(m_SubType, "SE "); } if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { m_Type = eWindowsME; } break; } case VER_PLATFORM_WIN32s: { m_Type = eWindows32; break; } } }
혹 조금이나마 도움이 되었다면 http://crowback.tistory.com 이곳에 감사인사 한 마디 정도 남기도록 하장.. ^^