구글


Window OS 종류 알아내기 ▶SW_Coding

#define OS_VERSION_WIN95 0x01
#define OS_VERSION_WIN98 0x02
#define OS_VERSION_WINME 0x03
#define OS_VERSION_WINXP 0x04
#define OS_VERSION_WINNT 0x05
#define OS_VERSION_WIN2000 0x06
#define OS_VERSION_WIN2003 0x07
#define OS_VERSION_WINNET 0x08
#define OS_VERSION_WINVISTA 0x09

#define OS_VERSION_WIN7    0x0A

BYTE CTest::GetOsVersion()
{
 OSVERSIONINFOEX osvi;
 BOOL bOsVersionInfoEx;
 CString strVer;
 CString ssvp;
 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
   {
      // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
         return OS_VERSION_WINXP;
   }

   switch (osvi.dwPlatformId)
   {
      // Tests for Windows NT product family.
      case VER_PLATFORM_WIN32_NT:

      // Test for the product.

    if ( osvi.dwMajorVersion <= 4 ) {
            //strVer = "Microsoft Windows NT ";
   return OS_VERSION_WINXP;
    }
   
    // Window Vista

    if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
    {
            strVer = "Microsoft Windows Vista ";
   return OS_VERSION_WINVISTA;
    }

    // Window 7

    if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
    {
            strVer = "Microsoft Windows 7 ";
   return OS_VERSION_WIN7;
    }

    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
            strVer = "Microsoft Windows 2000 ";
   return OS_VERSION_WIN2000;
    }

         if( bOsVersionInfoEx )  // Use information from GetVersionEx.
         {
         // Test for the workstation type.
            if ( osvi.wProductType == VER_NT_WORKSTATION )
            {
    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) {
                  strVer = "Microsoft Windows XP ";
      return OS_VERSION_WINXP;
    }
    
    if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) {
                  strVer =  strVer+ " Home Edition ";
      return OS_VERSION_WINXP;
    } else {
                  strVer =  strVer+ "Professional " ;
      return OS_VERSION_WINXP;
    }
            }

         // Test for the server type.
            else if ( osvi.wProductType == VER_NT_SERVER )
            {
    if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {
                  strVer = "Microsoft Windows .NET ";
      return OS_VERSION_WINNET;
    }
    if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) {
                  strVer =  strVer + "DataCenter Server " ;
      return OS_VERSION_WINNET;
    }
    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) {
     if( osvi.dwMajorVersion == 4 ) {
      strVer = strVer +  "Advanced Server " ;
      return OS_VERSION_WINNET;
     }  else {
      strVer = strVer +   "Enterprise Server " ;
      return OS_VERSION_WINNET;
     }
    } else if ( osvi.wSuiteMask == VER_SUITE_BLADE ) {
                  strVer = strVer +   "Web Server " ;
      return OS_VERSION_WINNET;
    } else {
                  strVer = strVer +    "Server " ;
      return OS_VERSION_WINNET;
    }
            }
         }
         else   // Use the registry on early versions of Windows NT.
         {
            HKEY hKey;
            char szProductType[1024];
            DWORD dwBufLen=1024;
            LONG lRet;

            lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
               "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
               0, KEY_QUERY_VALUE, &hKey );
            if( lRet != ERROR_SUCCESS )
                return OS_VERSION_WINXP;

            lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
               (LPBYTE) szProductType, &dwBufLen);
            if( (lRet != ERROR_SUCCESS) || (dwBufLen > 1024) )
                return OS_VERSION_WINXP;

            RegCloseKey( hKey );

            if ( lstrcmpi( "WINNT", szProductType) == 0 ) {
               strVer =    " Win NT Professional " ;
      return OS_VERSION_WINNT;
   }
            if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) {
               strVer =  " Win NT Server " ;
      return OS_VERSION_WINNT;
   }
            if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) {
               strVer +  " Win NT Advanced Server " ;
    return OS_VERSION_WINNT;
   }
         }

      // Display version, service pack (if any), and build number.

         if ( osvi.dwMajorVersion <= 4 )
         {
            ssvp.Format("version %d.%d %s (Build %d)\n",
               osvi.dwMajorVersion,
               osvi.dwMinorVersion,
               osvi.szCSDVersion,
               osvi.dwBuildNumber & 0xFFFF);
         }
         else
         {
            ssvp.Format("%s (Build %d)\n",
               osvi.szCSDVersion,
               osvi.dwBuildNumber & 0xFFFF);
         }
         break;

      // Test for the Windows 95 product family.
      case VER_PLATFORM_WIN32_WINDOWS:

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
         {
             strVer = "Microsoft Windows 95 ";
             if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) {
                strVer = strVer + "OSR2 " ;
    return OS_VERSION_WIN95;
    }
         }

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
         {
             strVer = "Microsoft Windows 98 ";
             if ( osvi.szCSDVersion[1] == 'A' ) {
                strVer =  strVer + "SE " ;
    return OS_VERSION_WIN98;
    }   
         }

         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
         {
             strVer =  strVer +  "Microsoft Windows Millennium Edition ";
    return OS_VERSION_WINME;
         }
         break;
   }
   return OS_VERSION_WINXP;
}




덧글

  • kuma 2009/12/21 22:02 # 삭제 답글

    안녕하세요.. GetOSInfo 검색 하다가 들렸습니다.
    제가 예전에 구현 해놓은 코드랑 비슷하네요..; Windows 7 Version 이 변경 되었습니다..
    저도 예전에 RC 베타 버전일때는 6.7 로 하면 Windows 7 으로 나왔던거로 기억하는데요..
    6.1 버전으로 변경 되었습니다..따라서..
    if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
    {
    strVer = "Microsoft Windows 7 ";
    return OS_VERSION_WIN7;
    }

    위 문장으로 변경 되어야 합니다.ㅎ

    저도 6.7 로 체크하니까 Windows 7 으로 안나와서 MSDN 찾아보니까..
    6.1 로 바꿨네요.. ㅎ
    http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx

    그럼 수고하세요..ㅎ
  • 토리 2009/12/21 22:07 #

    그렇군요...^^
    감사합니다...
  • 그럴리가 2016/04/21 15:40 # 삭제 답글

    Win10에서 돌렸더니 XP라고 나오네요^^
  • 그럴리가 2016/04/21 15:40 # 삭제 답글

    Win10에서 돌렸더니 XP라고 나오네요^^
댓글 입력 영역