获取windows系统的版本名称

windows系统的版本信息从OSVERSIONINFO 结构体获取,该结构体的详细定义如下:</span>
 
<pre name="code" class="cpp">typedef struct _OSVERSIONINFOA {
    DWORD dwOSVersionInfoSize;
    DWORD dwMajorVersion;//主版本号
    DWORD dwMinorVersion;//次版本号
    DWORD dwBuildNumber;
    DWORD dwPlatformId;
    CHAR   szCSDVersion[ 128 ];     // Maintenance string for PSS usage
} OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;

 
 
void GetSystemName(std::string &strOsName)
{
	SYSTEM_INFO info;        
	GetSystemInfo(&info);    
	OSVERSIONINFOEX os; 
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);   
	strOsName = _T("unknown OperatingSystem.");
	if(GetVersionEx((OSVERSIONINFO *)&os))
	{ 

		switch(os.dwMajorVersion) 
		{
		case 4:
			switch(os.dwMinorVersion) 
			{ 
			case 0:
				if(os.dwPlatformId == VER_PLATFORM_WIN32_NT)
					strOsName =_T("Windows NT 4.0");  
				else if(os.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
					strOsName =_T("Windows 95");
				break;
			case 10:
				strOsName =_T("Windows 98");
				break;
			case 90:
				strOsName =_T("Windows Me");
				break;
			}
			break;

		case 5:
			switch(os.dwMinorVersion) 
			{ 
			case 0:
				strOsName =_T("Windows 2000"); 
				break;

			case 1:
				strOsName =_T("Windows XP"); 
				break;

			case 2:
				if(os.wProductType==VER_NT_WORKSTATION 
					&& info.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
				{
					strOsName =_T("Windows XP Professional x64 Edition");
				}
				else if(GetSystemMetrics(SM_SERVERR2)==0)
					strOsName =_T("Windows Server 2003"); 
				else if(GetSystemMetrics(SM_SERVERR2)!=0)
					strOsName =_T("Windows Server 2003 R2");
				break;
			}
			break;

		case 6:
			switch(os.dwMinorVersion)
			{
			case 0:
				if(os.wProductType == VER_NT_WORKSTATION)
					strOsName =_T("Windows Vista");
				else
					strOsName =_T("Windows Server 2008"); 
				break;
			case 1:
				if(os.wProductType == VER_NT_WORKSTATION)
					strOsName =_T("Windows 7");	
				else
					strOsName =_T("Windows Server 2008 R2");
				break;
			case 2:
				if(os.wProductType == VER_NT_WORKSTATION)
					strOsName =_T("Windows 8");	
				else
					strOsName =_T("Windows Server 2012");
				break;
			case 3:
				if(os.wProductType == VER_NT_WORKSTATION)
					strOsName =_T("Windows 8.1");	
				else
					strOsName =_T("Windows Server 2012 R2");
				break;
			}
			break;
		}
	} 

} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值