// GetWindowsVersion.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
// NTDLL의 RtlGetVersion() 함수에서 알수가 있었습니다
// 현재 사용하고 있는 운영체제의 버젼을 PEB정보를 통하여 가져옵니다
// 잘못되었거나, 궁금한점이 있으시면
seyool@dreamwiz.com로 알려주세요 ^^
/* -------------------------------------------------------------------
Operating system Version number
-------------------------------------------------------------------
Windows Server "Longhorn" 6.0
Windows Vista 6.0
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 5.1
Windows 2000 5.0
Windows Me 4.90
Windows 98 4.10
Windows NT 4.0 4.0
Windows 95 4.0
------------------------------------------------------------------ */
#include "stdafx.h"
#include <windows.h>
void GetWindowsVersion(PULONG pMajorVersion, PULONG pMinorVersion)
{
_asm
{
push edi
push esi
mov eax, dword ptr fs:[18h]
mov edi, dword ptr ds:[eax+30h]
; Get Major Version
mov eax, dword ptr ds:[edi+0A4h]
mov esi, [pMajorVersion]
mov dword ptr ds:[esi], eax
; Get Minor Version
mov eax, dword ptr ds:[edi+0A8h]
mov esi, [pMinorVersion]
mov dword ptr ds:[esi], eax
pop esi
pop edi
}
}
int _tmain(int argc, _TCHAR* argv[])
{
ULONG ma, mi;
GetWindowsVersion(&ma, &mi);
printf("Current Windows version %X.%X\n", ma, mi);
return 0;
}
getversion.zip