Windows 系统版本判断
很多情况下,需要软件判断操作系统,其实网上写的都很少,我希望这篇文章能给大家帮助
首先我们要在.h中定义下面的东西
- #define PRODUCT_UNDEFINED 0x00000000
- #define PRODUCT_ULTIMATE 0x00000001
- #define PRODUCT_HOME_BASIC 0x00000002
- #define PRODUCT_HOME_PREMIUM 0x00000003
- #define PRODUCT_ENTERPRISE 0x00000004
- #define PRODUCT_HOME_BASIC_N 0x00000005
- #define PRODUCT_BUSINESS 0x00000006
- #define PRODUCT_STANDARD_SERVER 0x00000007
- #define PRODUCT_DATACENTER_SERVER 0x00000008
- #define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
- #define PRODUCT_ENTERPRISE_SERVER 0x0000000A
- #define PRODUCT_STARTER 0x0000000B
- #define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
- #define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
- #define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
- #define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
- #define PRODUCT_BUSINESS_N 0x00000010
- #define PRODUCT_WEB_SERVER 0x00000011
- #define PRODUCT_CLUSTER_SERVER 0x00000012
- #define PRODUCT_HOME_SERVER 0x00000013
- #define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
- #define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
- #define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
- #define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
- #define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
- #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
- #define PRODUCT_UNLICENSED 0xABCDABCD
好了,这是必须的定义,为了就是判断操作系统
下面是判断操作系统的代码
- #include <windows.h>
- #include <tchar.h>
- #include <stdio.h>
- #include <strsafe.h>
- #pragma comment(lib, "User32.lib")
- #define BUFSIZE 256
- typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
- typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
- BOOL GetOSDisplayString( LPTSTR pszOS)
- {
- OSVERSIONINFOEX osvi;
- SYSTEM_INFO si;
- PGNSI pGNSI;
- PGPI pGPI;
- BOOL bOsVersionInfoEx;
- DWORD dwType;
- ZeroMemory(&si, sizeof(SYSTEM_INFO));
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi);
- if(bOsVersionInfoEx != NULL ) return 1;
- // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
- pGNSI = (PGNSI) GetProcAddress(
- GetModuleHandle(TEXT("kernel32.dll")),
- "GetNativeSystemInfo");
- if(NULL != pGNSI)
- pGNSI(&si);
- else GetSystemInfo(&si);
- if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&
- osvi.dwMajorVersion > 4 )
- {
- StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft "));
- // Test for the specific product.
- if ( osvi.dwMajorVersion == 6 )
- {
- if( osvi.dwMinorVersion == 0 )
- {
- if( osvi.wProductType == VER_NT_WORKSTATION )
- StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista "));
- else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 " ));
- }
- if ( osvi.dwMinorVersion == 1 )
- {
- if( osvi.wProductType == VER_NT_WORKSTATION )
- StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 "));
- else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 " ));
- }
- pGPI = (PGPI) GetProcAddress(
- GetModuleHandle(TEXT("kernel32.dll")),
- "GetProductInfo");
- pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
- switch( dwType )
- {
- case PRODUCT_ULTIMATE:
- StringCchCat(pszOS, BUFSIZE, TEXT("Ultimate Edition" ));
- break;
- case PRODUCT_PROFESSIONAL:
- StringCchCat(pszOS, BUFSIZE, TEXT("Professional" ));
- break;
- case PRODUCT_HOME_PREMIUM:
- StringCchCat(pszOS, BUFSIZE, TEXT("Home Premium Edition" ));
- break;
- case PRODUCT_HOME_BASIC:
- StringCchCat(pszOS, BUFSIZE, TEXT("Home Basic Edition" ));
- break;
- case PRODUCT_ENTERPRISE:
- StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
- break;
- case PRODUCT_BUSINESS:
- StringCchCat(pszOS, BUFSIZE, TEXT("Business Edition" ));
- break;
- case PRODUCT_STARTER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Starter Edition" ));
- break;
- case PRODUCT_CLUSTER_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Cluster Server Edition" ));
- break;
- case PRODUCT_DATACENTER_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition" ));
- break;
- case PRODUCT_DATACENTER_SERVER_CORE:
- StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition (core installation)" ));
- break;
- case PRODUCT_ENTERPRISE_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
- break;
- case PRODUCT_ENTERPRISE_SERVER_CORE:
- StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition (core installation)" ));
- break;
- case PRODUCT_ENTERPRISE_SERVER_IA64:
- StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems" ));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server" ));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
- StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server Premium Edition" ));
- break;
- case PRODUCT_STANDARD_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition" ));
- break;
- case PRODUCT_STANDARD_SERVER_CORE:
- StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition (core installation)" ));
- break;
- case PRODUCT_WEB_SERVER:
- StringCchCat(pszOS, BUFSIZE, TEXT("Web Server Edition" ));
- break;
- }
- }
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
- {
- if( GetSystemMetrics(SM_SERVERR2) )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Server 2003 R2, "));
- else if ( osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Storage Server 2003"));
- else if ( osvi.wSuiteMask & VER_SUITE_WH_SERVER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Home Server"));
- else if( osvi.wProductType == VER_NT_WORKSTATION &&
- si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
- {
- StringCchCat(pszOS, BUFSIZE, TEXT( "Windows XP Professional x64 Edition"));
- }
- else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, "));
- // Test for the server type.
- if ( osvi.wProductType != VER_NT_WORKSTATION )
- {
- if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
- {
- if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition for Itanium-based Systems" ));
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition for Itanium-based Systems" ));
- }
- else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
- {
- if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter x64 Edition" ));
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise x64 Edition" ));
- else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard x64 Edition" ));
- }
- else
- {
- if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Compute Cluster Edition" ));
- else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition" ));
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition" ));
- else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Web Edition" ));
- else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard Edition" ));
- }
- }
- }
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
- {
- StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP "));
- if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Home Edition" ));
- else StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
- }
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
- {
- StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 "));
- if ( osvi.wProductType == VER_NT_WORKSTATION )
- {
- StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
- }
- else
- {
- if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Server" ));
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- StringCchCat(pszOS, BUFSIZE, TEXT( "Advanced Server" ));
- else StringCchCat(pszOS, BUFSIZE, TEXT( "Server" ));
- }
- }
- // Include service pack (if any) and build number.
- if( _tcslen(osvi.szCSDVersion) > 0 )
- {
- StringCchCat(pszOS, BUFSIZE, TEXT(" ") );
- StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
- }
- TCHAR buf[80];
- StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
- StringCchCat(pszOS, BUFSIZE, buf);
- if ( osvi.dwMajorVersion >= 6 )
- {
- if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
- StringCchCat(pszOS, BUFSIZE, TEXT( ", 64-bit" ));
- else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
- StringCchCat(pszOS, BUFSIZE, TEXT(", 32-bit"));
- }
- return TRUE;
- }
- else
- {
- printf( "This sample does not support this version of Windows.\n");
- return FALSE;
- }
- }
- int __cdecl _tmain()
- {
- TCHAR szOS[BUFSIZE];
- if( GetOSDisplayString( szOS ) )
- _tprintf( TEXT("\n%s\n"), szOS );
- }
参照:
Operating system Version number dwMajorVersiondwMinorVersion Other
Windows 8 | 6.2 | 6 | 2 | OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION |
Windows Server 2012 | 6.2 | 6 | 2 | OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION |
Windows 7 | 6.1 | 6 | 1 | OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION |
Windows Server 2008 R2 | 6.1 | 6 | 1 | OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION |
Windows Server 2008 | 6.0 | 6 | 0 | OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION |
Windows Vista | 6.0 | 6 | 0 | OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION |
Windows Server 2003 R2 | 5.2 | 5 | 2 | GetSystemMetrics(SM_SERVERR2) != 0 |
Windows Home Server | 5.2 | 5 | 2 | OSVERSIONINFOEX.wSuiteMask & VER_SUITE_WH_SERVER |
Windows Server 2003 | 5.2 | 5 | 2 | GetSystemMetrics(SM_SERVERR2) == 0 |
Windows XP Professional x64 Edition | 5.2 | 5 | 2 | (OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION) && (SYSTEM_INFO.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) |
Windows XP | 5.1 | 5 | 1 | Not applicable |
Windows 2000 | 5.0 | 5 | 0 | Not applicable |
好了,还有就是要提供出处了:
http://msdn.microsoft.com/en-us/library/ms724429(v=vs.85).aspx
http://msdn.microsoft.com/ja-jp/library/windows/desktop/ms724833(v=vs.85).aspx
http://www.usefullcode.net/2006/12/windows_vista_2.html
Windows 系统版本判断的更多相关文章
- Windows系统版本判定那些事儿
v:* { } o:* { } w:* { } .shape { }p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-botto ...
- Windows系统版本判定那些事儿[转]
Windows系统版本判定那些事儿 转自CSDN,原文链接,我比较不要脸, 全部给复制过来了 前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度 ...
- inno setup判断是Windows系统版本(其实还是Delphi代码,还能检查域控制器和家庭版)
1.设置Windows最低版本要求 [Setup]: MinVersion 格式: a.bb,c.dd,这里 a.bb 是 Windows 版本,c.dd 是 Windows NT 版本. 默认值: ...
- Windows系统版本判定那些事儿(有图,各种情况,很清楚)
前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度讨论下Windows获取系统版本的方法和遇到的一些问题.在Win8和Win10出来之后,在获取 ...
- Delphi 10.3版本获取windows系统版本和CPU信息
procedure TForm1.Button1Click(Sender: TObject); var mm:TRegistry; cpu:string; begin mm:=TRegistry.Cr ...
- Windows系统版本型号MSDN版、OEM版、RTM版、VOL版区别
我们常常听说操作系统的MSDN版.OEM版.RTM版.VOL版等等,它们到底是什么意思,有什么不同呢? (一)MSDN (Microsoft Developer Network)版MSDN软件是微软公 ...
- cmd提取时间格式(小时)问题以及Windows系统语言判断
你在这里看到了我的现在的时间是01:15,没错正在做个开发,本来好好的,结果一运行,直接报错: 这里就是时间中的获取小时出了问题,之前23点那会已经调试通过了,过那时是没有问题的,那么这时发生了什么? ...
- 也谈如何获取真实正确的 Windows 系统版本号
关于 GetVersion 系列接口 关于如何获取 Windows 系统版本号的话题,网上已经有了太多的帖子.但个人觉得总结的都不尽全面,或者没有给出比较稳定的解决方案. 众所周知,获取 Window ...
- 使用bat脚本永久激活Windows系统
每次重装完系统后,右下角会提示系统未激活,无法进行一些个性化设置. 在这里我自己写了一个bat脚本用于激活Windows系统.(仅供学习) 文件下载: 链接:https://pan.baidu.com ...
随机推荐
- python:unittest(测试框架)
一,基本概念 TestCase:所有测试用例的基类 TestLoad:加载测试用例,返回TestSuite(测试套件) TestSuite:创建测试套件 TextTestRunner:运行测试用例 T ...
- JS 实现显示和隐藏div(以百度地图为例)
主要参考的文章:https://my.oschina.net/xsh1208/blog/215811,https://zhidao.baidu.com/question/568774688.html ...
- Unity3D基础学习 加载场景时隐藏物体,点击显示时显示物体
隐藏物体有两种方法,一是设置Meshrender为False,即不渲染物体. 二是设置物体为False,禁用物体,我使用的第二种. 当场景中需要隐藏的物体很多时,我们可以添加一个层来表示需要隐藏的物体 ...
- log4j级别输出
log4j 我们知道: log4j.logger.XX cover ==> log4j.rootLogger log4j.appender.XX.Threshold决定了最低接收级别 也就是说 ...
- java JMS消息队列
http://blog.csdn.net/shirdrn/article/details/6362792 http://haohaoxuexi.iteye.com/blog/1893038 http: ...
- Unix系统解压tar包时出现@LongLink错误
Unix系统上使用tar命令解压tar包后,多了一个@LongLink的文件,并且原来的tar包解压后不完整.网上查了下,原因是AIX系统上tar命令自身的一个缺陷.解决办法:把该tar包上传到lin ...
- MediaPlayer 音频播放 示例
状态机.流程图.生命周期 对播放音频/视频文件和流的控制是通过一个状态机来管理的.下图显示一个MediaPlayer对象被支持的播放控制操作驱动的生命周期和状态. 椭圆代表MediaPlayer对象可 ...
- SpringMVC09异常处理和类型转化器
public class User { private String name; private Integer age; public String getName() { return name; ...
- html01基本标签
01. <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8 ...
- HDU3757
题意:一些团队因为任务要去避难所,并且每个避难所必须要有团队在,避难所的数量小于等于团队的数量, 团队去避难所的消耗油量与路程成正比,求解最小耗油量.题目来源:2010 Northeastern Eu ...