운영체제 버전 구하기

@codemaru · August 29, 2007 · 13 min read

정확한 OS 종류를 판단하는 것은 무척 중요한 일 입니다. 이 문서에 포함된 함수들은 VerifyVersion과 GetVersionEx함수를 사용하여 정확한 OS 종류를 판단합니다. 제공되는 함수는 아래와 같습니다. 각각의 함수가 판별하는 OS는 주석을 참고 하십시요.

```cpp
BOOL WINAPI IsWin95()          // 윈도우 95  
BOOL WINAPI IsWin95OSR2()      // 윈도우 95 OSR2  
BOOL WINAPI IsWin98()          // 윈도우 98  
BOOL WINAPI IsWin98SE()        // 윈도우 98 SE  
BOOL WINAPI IsWinME()          // 윈도우 ME  
BOOL WINAPI IsWin9X()          // 모든 윈도우 9x 시스템  
BOOL WINAPI IsWinNT4()         // 윈도우 NT4  
BOOL WINAPI IsWin2K()          // 윈도우 2000  
BOOL WINAPI IsWinXP()          // 윈도우 XP  
BOOL WINAPI IsWinNET()         // 윈도우 .Net  
BOOL WINAPI IsWinNT()          // 모든 윈도우 NT계열 시스템
```cpp
#ifndef GETPROC  
#define GETPROC(dll, type, name) (type)GetProcAddress(dll, name)  
#endif  
  
typedef BOOL   
(WINAPI \*fnVerifyVersionInfo)(LPOSVERSIONINFOEX, DWORD, DWORDLONG);  
  
typedef ULONGLONG   
(WINAPI \*fnVerSetConditionMask)(ULONGLONG, DWORD, BYTE);  
  
BOOL \_VerifyVersionInfo(LPOSVERSIONINFOEX lpVersionInfo  
                        , DWORD dwTypeMask  
                        , DWORDLONG dwConditionMask  
                        , BOOL \*bVerified)  
{  
    BOOL bRet = FALSE;  
    HINSTANCE hDll = NULL;  
    fnVerifyVersionInfo FVerifyVersionInfo;  
    fnVerSetConditionMask FVerSetConditionMask;  
  
    hDll = LoadLibrary("kernel32.dll");  
    if(hDll != NULL)  
    {  
        FVerifyVersionInfo = GETPROC(hDll  
                                    , fnVerifyVersionInfo  
                                    , "VerifyVersionInfoA");  
  
        FVerSetConditionMask = GETPROC(hDll  
                                    , fnVerSetConditionMask  
                                    , "VerSetConditionMask");  
  
        if(FVerifyVersionInfo != NULL && FVerSetConditionMask != NULL)  
        {  
            dwConditionMask = 0;  
            if(dwTypeMask & VER\_MAJORVERSION)  
                dwConditionMask = FVerSetConditionMask(dwConditionMask  
                                                    , VER\_MAJORVERSION  
                                                    , VER\_EQUAL);  
  
            if(dwTypeMask & VER\_MINORVERSION)  
                dwConditionMask = FVerSetConditionMask(dwConditionMask  
                                                    , VER\_MINORVERSION  
                                                    , VER\_EQUAL);  
  
            if(dwTypeMask & VER\_PLATFORMID)  
                dwConditionMask = FVerSetConditionMask(dwConditionMask  
                                                    , VER\_PLATFORMID  
                                                    , VER\_EQUAL);  
  
            if(dwTypeMask & VER\_PRODUCT\_TYPE)  
                dwConditionMask = FVerSetConditionMask(dwConditionMask  
                                                        , VER\_PRODUCT\_TYPE  
                                                        , VER\_EQUAL);  
  
  
            \*bVerified = FVerifyVersionInfo(lpVersionInfo  
                                            , dwTypeMask  
                                            , dwConditionMask);  
            bRet = TRUE;  
        }  
        FreeLibrary(hDll);  
    }  
  
    return bRet;  
}  
  
BOOL WINAPI IsWin95()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 0;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi  
                        , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                        , dwlConditionMask  
                        , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }  
  
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 0)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS)   
            && (osi.szCSDVersion[1] != 'C');  
}  
  
BOOL WINAPI IsWin95OSR2()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 0;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi  
                                , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                                , dwlConditionMask  
                                , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 0)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS)   
            && (osi.szCSDVersion[1] == 'C');  
}  
  
BOOL WINAPI IsWin98()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 10;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi  
                            , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                            , dwlConditionMask  
                            , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 10)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS)   
            && (osi.szCSDVersion[1] != 'A');  
}  
  
BOOL WINAPI IsWin98SE()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 10;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi  
                            , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                            , dwlConditionMask  
                            , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 10)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS)   
            && (osi.szCSDVersion[1] == 'A');  
}  
  
BOOL WINAPI IsWinME()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 90;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi  
                            , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                            , dwlConditionMask  
                            , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
  
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 90)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS);  
}  
  
BOOL WINAPI IsWin9X()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_WINDOWS;  
  
    bRet = \_VerifyVersionInfo(&osi, VER\_PLATFORMID, dwlConditionMask, &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
  
    return osi.dwPlatformId == VER\_PLATFORM\_WIN32\_WINDOWS;  
}  
  
BOOL WINAPI IsWinNT4()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 4;  
    osi.dwMinorVersion = 0;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_NT;  
  
    bRet = \_VerifyVersionInfo(&osi  
                        , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                        , dwlConditionMask  
                        , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 4)   
            && (osi.dwMinorVersion == 0)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_NT);  
}  
  
BOOL WINAPI IsWin2K()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 5;  
    osi.dwMinorVersion = 0;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_NT;  
  
    bRet = \_VerifyVersionInfo(&osi  
                        , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                        , dwlConditionMask  
                        , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 5)   
            && (osi.dwMinorVersion == 0)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_NT);  
}  
  
BOOL WINAPI IsWinXP()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 5;  
    osi.dwMinorVersion = 1;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_NT;  
  
    bRet = \_VerifyVersionInfo(&osi  
                        , VER\_MAJORVERSION | VER\_MINORVERSION | VER\_PLATFORMID  
                        , dwlConditionMask  
                        , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return  (osi.dwMajorVersion == 5)   
            && (osi.dwMinorVersion == 1)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_NT)   
            && (osi.wProductType == VER\_NT\_WORKSTATION);  
}  
  
BOOL WINAPI IsWinNET()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwMajorVersion = 5;  
    osi.dwMinorVersion = 1;  
    osi.wProductType = VER\_NT\_WORKSTATION;  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_NT;  
  
    DWORD type = VER\_MAJORVERSION   
                | VER\_MINORVERSION   
                | VER\_PRODUCT\_TYPE   
                | VER\_PLATFORMID;  
  
    bRet = \_VerifyVersionInfo(&osi, type, dwlConditionMask, &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
      
    return (osi.dwMajorVersion == 5)   
            && (osi.dwMinorVersion == 1)   
            && (osi.dwPlatformId == VER\_PLATFORM\_WIN32\_NT)   
            && (osi.wProductType != VER\_NT\_WORKSTATION);  
}  
  
BOOL WINAPI IsWinNT()  
{  
    OSVERSIONINFOEX osi;  
    DWORDLONG dwlConditionMask = 0;  
    BOOL bRet = FALSE;  
    BOOL bVerified = FALSE;  
  
    ZeroMemory(&osi, sizeof(OSVERSIONINFOEX));  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    osi.dwPlatformId = VER\_PLATFORM\_WIN32\_NT;  
  
    bRet = \_VerifyVersionInfo(&osi  
                            , VER\_PLATFORMID  
                            , dwlConditionMask  
                            , &bVerified);  
    if(bRet == TRUE)  
        return bVerified;  
  
    osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);  
    if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
    {  
        osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);  
        if(GetVersionEx((OSVERSIONINFO \*) &osi) == 0)  
            return 0;  
    }         
  
    return osi.dwPlatformId == VER\_PLATFORM\_WIN32\_NT;  
}
@codemaru
돌아보니 좋은 날도 있었고, 나쁜 날도 있었다. 그런 나의 모든 소소한 일상과 배움을 기록한다. 여기에 기록된 모든 내용은 한 개인의 관점이고 의견이다. 내가 속한 조직과는 1도 상관이 없다.
(C) 2001 YoungJin Shin, 0일째 운영 중