欢迎来到天天文库
浏览记录
ID:51489744
大小:108.45 KB
页数:4页
时间:2020-03-25
《编程获取Windows的版本.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Windows编程编程获取Windows的版本摘要:介绍通过编程的方法判断Windows是XP、win7还是win8。用到的内容包括函数GetVersionEx,结构体OSVERSIONINFO和OSVERSIONINFOEX。关键字:GetVersionExOSVERSIONINFOOSVERSIONINFOEX版本判断一首先给出示例代码/******************************************函数名:GetSysVersion参数:返回值:stringXP2000Vistawin7win8w
2、in8.1false失败old2000以前的版本功能:获取操作系统版本******************************************/stringGetSysVersion(){OSVERSIONINFOOSVersionInfo;memset(&OSVersionInfo,0,sizeof(OSVERSIONINFO));OSVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);if(!GetVersionEx(&OSVersionInfo)){
3、return"false";}if(VER_PLATFORM_WIN32_NT==OSVersionInfo.dwPlatformId){if(5==OSVersionInfo.dwMajorVersion&&0==OSVersionInfo.dwMinorVersion){return"2000";}if(5==OSVersionInfo.dwMajorVersion&&1==OSVersionInfo.dwMinorVersion){return"XP";}if(6==OSVersionInfo.dwMajorVers
4、ion&&0==OSVersionInfo.dwMinorVersion){return"Vista";}if(6==OSVersionInfo.dwMajorVersion&&1==OSVersionInfo.dwMinorVersion){return"win7";}if(6==OSVersionInfo.dwMajorVersion&&2==OSVersionInfo.dwMinorVersion){return"win8";}if(6==OSVersionInfo.dwMajorVersion&&3==OSVers
5、ionInfo.dwMinorVersion){return"win8.1";}第1页共4页Windows编程}else{return"old";}return"false";}二对用到的函数和结构体作一下说明OSVERSIONINFOtypedefstruct_OSVERSIONINFO{DWORDdwOSVersionInfoSize;//这个结构体的大小,在使用前必须初始化DWORDdwMajorVersion;//主版本号DWORDdwMinorVersion;//副版本号DWORDdwBuildNumber;//
6、buildnumberDWORDdwPlatformId;//平台的IDVER_PLATFORM_WIN32_NTTCHARszCSDVersion[128];//一些附加的信息如"ServicePack3"}OSVERSIONINFO;关于主版本号和副版本号见第三部分的对照表。OSVERSIONINFOEXtypedefstruct_OSVERSIONINFOEX{DWORDdwOSVersionInfoSize;DWORDdwMajorVersion;DWORDdwMinorVersion;DWORDdwBuildNu
7、mber;DWORDdwPlatformId;TCHARszCSDVersion[128];WORDwServicePackMajor;//服务升级包主版本号WORDwServicePackMinor;WORDwSuiteMask;BYTEwProductType;BYTEwReserved;}OSVERSIONINFOEX,*POSVERSIONINFOEX,*LPOSVERSIONINFOEX;是上面结构体体的扩展,增加了部分信息。具体见msdn扩展的信息如是家庭版等。GetVersionExBOOLGetVersio
8、nEx(LPOSVERSIONINFOlpVersionInformation//pointertoversioninformationstructure);功能:获取系统的版本信息。参数:LPOSVERSIONINFOlpVersionInformation指向OSVERSIONINFO的结构体。第2
此文档下载收益归作者所有