admin 管理员组

文章数量: 887021

主要用到的windowsAPI为GetVersion()函数
代码

#define WIN10_VERSION 1
#define WIN7_VERSION 2

//获取当前系统版本
DWORD getCurrentSystemVersion()
{
	DWORD dwVersion = GetVersion();
	DWORD dwMajorVer =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
	DWORD dwMinorVer =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
	if (dwMajorVer > 6)
		return WIN10_VERSION;
	else if (dwMajorVer >= 6 && dwMinorVer >= 2)
		return WIN10_VERSION;
	else
		return WIN7_VERSION;
}

使用方法

// WinDemo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#define WIN10_VERSION 1
#define WIN7_VERSION 2

//获取当前系统版本
DWORD getCurrentSystemVersion()
{
	DWORD dwVersion = GetVersion();
	DWORD dwMajorVer =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
	DWORD dwMinorVer =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
	if (dwMajorVer > 6)
		return WIN10_VERSION;
	else if (dwMajorVer >= 6 && dwMinorVer >= 2)
		return WIN10_VERSION;
	else
		return WIN7_VERSION;
}

int _tmain(int argc, _TCHAR* argv[])
{ 
	DWORD cur_version = getCurrentSystemVersion();
	if (cur_version == WIN10_VERSION)
	{
		std::cout << "当前版本为WIN10"<< std::endl;
	}
	else{
		std::cout << "当前版本为WIN7"<< std::endl;
	}
	system("pause");
	return 0;
}

运行结果:

本文标签: 系统 版本号 版本 Windows