C++ 获取windows系统版本号

#include
#include

BOOL GetNtVersionNumbers(DWORD& dwMajorVer, DWORD& dwMinorVer,DWORD& dwBuildNumber)
{
    BOOL bRet= FALSE;
    HMODULE hModNtdll= NULL;
    if (hModNtdll= ::LoadLibraryW(L"ntdll.dll"))
    {
        typedef void (WINAPI *pfRTLGETNTVERSIONNUMBERS)(DWORD*,DWORD*, DWORD*);
        pfRTLGETNTVERSIONNUMBERS pfRtlGetNtVersionNumbers;
        pfRtlGetNtVersionNumbers = (pfRTLGETNTVERSIONNUMBERS)::GetProcAddress(hModNtdll, "RtlGetNtVersionNumbers");
        if (pfRtlGetNtVersionNumbers)
        {
           pfRtlGetNtVersionNumbers(&dwMajorVer, &dwMinorVer,&dwBuildNumber);
           dwBuildNumber&= 0x0ffff;
           bRet = TRUE;
        }
 
        ::FreeLibrary(hModNtdll);
        hModNtdll = NULL;
    }
 
    return bRet;
}

//判断是否为64位操作系统
BOOL IsWow64()
{
	typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
	LPFN_ISWOW64PROCESS fnIsWow64Process;
	BOOL bIsWow64 = FALSE;
	fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
	if (NULL != fnIsWow64Process)
	{
		fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
	}
	return bIsWow64;
}

void main()
{
	DWORD dwMajorVer,dwMinorVer,dwBuildNumber;
	if (GetNtVersionNumbers(dwMajorVer,dwMinorVer,dwBuildNumber))
	printf("Build Version = %d.\%d.%d\n", dwMajorVer,dwMinorVer,dwBuildNumber);
	system("Pause");
}

系统版本号对应表

C++ 获取windows系统版本号_第1张图片 

 

你可能感兴趣的:(C++)