2016년 2월 20일 토요일

[VS2010 VC++] OSVersion.h 파일


////////////////////////////////////////////////////////////////////////////////////
//
// < COSVersion >
//
// Retrieve the Windows OS version.
//
// * AUTHOR
// Nam, in hyouk (GreenB)
//
// * ACKNOWLEDGEMENT
// Hans Dietrich(hdietrich@gmail.com)
// I found it by reference to his "CXWinVer" class.
// Please see his article at www.codeproject.com
//
// * HISTORY
// 2009-04-11 Initial release.
// 2010-12-06 IsWin7() added.
//
// * LICENCE
//     This software is released into the public domain. You are free to use
//     it in any way you like, except that you may not sell this source code.
//
//     This software is provided "as is" with no expressed or implied warranty.
//     I accept no liability for any damage or loss of business that this
//     software may cause.
//
//
// copyright(c) 2009-2010. GreenB. All right reserved.
// http://greenmaru.com
//
//
////////////////////////////////////////////////////////////////////////////////////
#ifndef _GREENB_OSVERSION_
#define _GREENB_OSVERSION_
#pragma once

#include <windows.h>

////////////////////////////////////////////////////////////////////////////////////
//
// COSVersion
//
////////////////////////////////////////////////////////////////////////////////////
class COSVersion
{
////////////////////////////////////////////////////////////////////////////////
// MEMBER VARS
////////////////////////////////////////////////////////////////////////////////
private:
OSVERSIONINFOEX m_osver;

////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTION
////////////////////////////////////////////////////////////////////////////////
public:
COSVersion( void )
{
memset( &m_osver, NULL, sizeof( OSVERSIONINFOEX ) );
m_osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );

if ( GetVersionEx( reinterpret_cast<LPOSVERSIONINFO>(&m_osver) ) )
{
//
// Is NT4 SP6 or later?
//
if ( ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&  (m_osver.dwMajorVersion >= 5 ) )
{
memset( &m_osver, NULL, sizeof( OSVERSIONINFOEX ) );
m_osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
GetVersionEx( reinterpret_cast<LPOSVERSIONINFO>(&m_osver) );
}
}
}

~COSVersion( void )
{
}

////////////////////////////////////////////////////////////////////////////////
// PROPERTY
////////////////////////////////////////////////////////////////////////////////
public:
DWORD MajorVersion( void ) const
{
return m_osver.dwMajorVersion;
}

DWORD MinorVersion( void ) const
{
return m_osver.dwMinorVersion;
}

DWORD BuildNumber( void ) const
{
return ( m_osver.dwBuildNumber & 0xFFFF );
}

DWORD ServicePack( void ) const
{
int nServicePack = 0;
for ( int i = 0 ; ( m_osver.szCSDVersion[i] != _T('\0') ) && ( i < (sizeof(m_osver.szCSDVersion) / sizeof(TCHAR) ) ) ; i++ )
{
if ( _istdigit( m_osver.szCSDVersion[i] ) )
{
nServicePack = _ttoi( &m_osver.szCSDVersion[i] );
break;
}
}
return nServicePack;
}

//
// Windows 9x
//
BOOL IsWin9x( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && m_osver.dwMajorVersion == 4 )
return TRUE;
return FALSE;
}

//
// Windows NT
//
BOOL IsWinNT4( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 4 && m_osver.dwMinorVersion == 0 )
return TRUE;
return FALSE;
}
BOOL IsWinNT4SP6( void ) const
{
if ( IsWinNT4() && ServicePack() == 6 )
return TRUE;
return FALSE;
}

//
// Windows XP / 2000 / 2003
//
BOOL IsWinXp( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 5 && m_osver.dwMinorVersion == 1 )
return TRUE;
return FALSE;
}
BOOL IsWinXpSP2( void ) const
{
if ( IsWinXp() && ServicePack() == 2 )
return TRUE;
return FALSE;
}
BOOL IsWinXpHome( void ) const
{
if ( IsWinXp() && m_osver.wSuiteMask & VER_SUITE_PERSONAL )
return TRUE;
return FALSE;
}
BOOL IsWinXpPro( void ) const
{
if ( IsWinXp() && m_osver.wProductType == VER_NT_WORKSTATION && !IsWinXpHome() )
return TRUE;
return FALSE;
}
BOOL IsWinXpOrLater( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion >= 5 )
return TRUE;
return FALSE;
}

BOOL IsWin2000( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 5 && m_osver.dwMinorVersion == 0 )
return TRUE;
return FALSE;
}

BOOL IsWin2003( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 5 && m_osver.dwMinorVersion == 2 )
return TRUE;
return FALSE;
}

//
// Windows Vista / 2008 / 7
//
BOOL IsVista( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 6 && m_osver.dwMinorVersion == 0 && m_osver.wProductType == VER_NT_WORKSTATION )
return TRUE;
return FALSE;
}
BOOL IsVistaOrLater( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion >= 6 )
return TRUE;
return FALSE;
}

BOOL IsWin2008( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 6 && m_osver.dwMinorVersion == 0 && m_osver.wProductType != VER_NT_WORKSTATION )
return TRUE;
return FALSE;
}

BOOL IsWin7( void ) const
{
if ( m_osver.dwPlatformId == VER_PLATFORM_WIN32_NT && m_osver.dwMajorVersion == 6 && m_osver.dwMinorVersion == 1 && m_osver.wProductType == VER_NT_WORKSTATION )
return TRUE;
return FALSE;
}

//
// Retrieve the server or workstation
//
BOOL IsServerOS( void ) const
{
if ( m_osver.wProductType > VER_NT_WORKSTATION )
return TRUE;
return FALSE;
}

BOOL IsDomainController( void )
{
return ( m_osver.wProductType && VER_NT_DOMAIN_CONTROLLER );
}
};

댓글 없음:

댓글 쓰기