简单获取系统版本示例

一般由系统的dwMajorVersion和dwMinorVersion就可以得到系统版本:

Windows 3.0,

Windows 3.1,

Windows NT, 95(4.0),

Windows 2000  (5.0),

Windows XP    (5.1), ....

Windows 7     (6.1), ..... ,

Windows 8.1   (6.3)

struct WindowsNTOSInfo

{

DWORD dwMajorVersion;

DWORD dwMinorVersion;

WORD wServicePackMajor;

//const TCHAR * pcszOSDisplayName;

};

const WindowsNTOSInfo KnownVersionsOfWindows[] =

{

{ 6, 3, 0,   },//win8.1,server2012 r2

{ 6, 2, 0,   },//win8,server2012

{ 6, 1, 1,  },//win7,win2008r2 sp1

{ 6, 1, 0,  },//win7,win2008r2

{ 5, 1, 3,  },//winxp sp3

{ 5, 1, 2,  },//winxp sp2

{ 5, 1, 1,  },//winxp sp1

{ 5, 1, 0,  },//winxp

{ 6, 0, 2,  },//WinVista,server2008 SP2

{ 6, 0, 1,  },//WinVista,Server2008 Sp1

{ 6, 0, 0,  },//WinVista,Server2008

{ 5, 2, 2,  },//Windows Server 2003 Sp2

{ 5, 2, 1,  },//Windows Server 2003 Sp1

{ 5, 2, 0,  },//Windows Server 2003

{ 5, 1, 4,  }, //Windows Server 2000 Sp4

{ 5, 1, 3,  }, //Windows Server 2000 Sp3

{ 5, 1, 2,  }, //Windows Server 2000 Sp2

{ 5, 1, 2,  }, //Windows Server 2000 Sp1

{ 5, 1, 0,  }, //Windows Server 2000

};

以下程序可以得出系统是win7还是xp

1)采用VerifyVersionInfo函数

BOOL IsWin7()
{
	OSVERSIONINFOEX osvi;
	DWORDLONG dwlConditionMask = 0;

	// Initialize the OSVERSIONINFOEX structure.

	ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	osvi.dwMajorVersion = 6;
	osvi.dwMinorVersion = 1;
	//osvi.wServicePackMajor = 1;

	// Initialize the condition mask.

	VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION,
		VER_EQUAL);
	VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION,
		VER_EQUAL);
	//VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR,	VER_EQUAL);

	// Perform the test.

	return VerifyVersionInfo(
		&osvi,
		VER_MAJORVERSION | VER_MINORVERSION,
		dwlConditionMask);
}

BOOL IsXP()
{
	OSVERSIONINFOEX osvi;
	DWORDLONG dwlConditionMask = 0;

	// Initialize the OSVERSIONINFOEX structure.

	ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	osvi.dwMajorVersion = 5;
	osvi.dwMinorVersion = 1;
	//osvi.wServicePackMajor = 1;

	// Initialize the condition mask.

	VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION,
		VER_EQUAL);
	VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION,
		VER_EQUAL);
	//VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR,	VER_EQUAL);

	// Perform the test.

	return VerifyVersionInfo(
		&osvi,
		VER_MAJORVERSION | VER_MINORVERSION,
		dwlConditionMask);
}

int _tmain(int argc, TCHAR* argv[])
{
	if (IsWin7())
		cout << "win 7" << endl;
	else if (IsXP())
		cout << "xp" << endl;
	else
		cout << "unrecognized system" << endl;

	system("pause");
	return 0;
}

2).

#include <iostream>
#include <Windows.h>	 // VersionHelpers.h 依赖于 windows.h
#include <VersionHelpers.h> // Windows SDK 8.1 才有喔
using namespace std;
int main(void)
{
if (IsWindows8OrGreater())
cout << "Win 8" << endl;
else if (IsWindows7OrGreater())
cout << "Win 7" << endl;
else if (IsWindowsXPOrGreater())
cout << "xp" << endl;
else
cout << "unrecognized system" << endl;

system("pause");
}
时间: 2024-10-10 13:31:12

简单获取系统版本示例的相关文章

IOS 获取系统版本字符串,并且转化成float类型

pcDuino3下支持mmc启动,官方的Uboot是采用SPL框架实现的,因为内部的SRAM空间达到32K,我们完全可以在这32K空间内编写一个完整可用小巧的bootloader来完成引导Linux kernel的目的. 我们首先介绍下SPL框架,可以先看下<GNU ARM汇编--(十八)u-boot-采用nand_spl方式的启动方法>和<GNU ARM汇编--(十九)u-boot-nand-spl启动过程分析>,NAND_SPL也算是SPL框架下的一种模式. 当使用Nand f

获取系统版本信息和处理器信息

// GetSystemInfo.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <windows.h> #include <iomanip> using namespace std; int main() { SYSTEM_INFO systemInfo; GetSystemI

c# 获取系统版本,获取net framework 版本(Environment 类)

原文:c# 获取系统版本,获取net framework 版本(Environment 类) 1.获取当前操作系统版本信息 使用Environment.OSVersion 属性 获取包含当前平台标识符和版本号的 OperatingSystem 对象. 命名空间:  System程序集:  mscorlib(在 mscorlib.dll 中) 使用方法: Environment.OSversion.ToString(); 2.获取本机.net framework 版本信息 使用Environmen

获取系统版本,判断是windows还是Linux

package com.foresee.zxpt.common.utils; import java.util.Properties; /** * 获取系统版本 * @author GZ * */ public class OSUtils { /** * 判断是否是Linux * @return */ public static boolean isOSLinux() { Properties prop = System.getProperties(); String os = prop.get

[转]python使用ctypes模块调用windowsapi获取系统版本

#coding: utf-8 import win32ui import win32gui import win32con import win32api #https://mail.python.org/pipermail/python-win32/2009-April/009078.html ''' ico_x = win32api.GetSystemMetrics(win32con.SM_CXICON) ico_y = win32api.GetSystemMetrics(win32con.

【转】通过js获取系统版本以及浏览器版本

1 function getOsInfo() { 2 var userAgent = navigator.userAgent.toLowerCase(); 3 var name = 'Unknown'; 4 var version = "Unknown"; 5 if(userAgent.indexOf("win") > -1) { 6 name = "Windows"; 7 if(userAgent.indexOf("window

获取系统版本

using System;using System.Collections;using System.Globalization;using System.IO;using System.Net;using System.Runtime.InteropServices;using System.Security.Cryptography;using System.Text;using System.Text.RegularExpressions;using System.Threading;us

python实现获取系统版本和mac信息上传到指定接口

import os,platform,uuid,urllib.parse,urllib.request,json def BeforeSystemRequests(): ''' the systeminfo uploads to api of .. ''' def get_system_version(): system_name = platform.system() if system_name == 'Windows' and os.name == 'nt': system_machine

Android安卓获取ID号,本机号码,手机型号,系统版本

Mark一下 public void Msg1(String str) { Toast toast = new Toast(this); Toast toast1 = toast.makeText(this, str, Toast.LENGTH_LONG); toast1.show(); } //获取ID号 final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPH