您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 薪酬管理 > 判断操作系统的c++源代码
#includeWindows.h#includestring#includestdio.hvoidgetSystemName(){std::stringvname;//先判断是否为win8.1或win10typedefvoid(__stdcall*NTPROC)(DWORD*,DWORD*,DWORD*);HINSTANCEhinst=LoadLibrary(ntdll.dll);DWORDdwMajor,dwMinor,dwBuildNumber;NTPROCproc=(NTPROC)GetProcAddress(hinst,RtlGetNtVersionNumbers);proc(&dwMajor,&dwMinor,&dwBuildNumber);if(dwMajor==6&&dwMinor==3)//win8.1{vname=MicrosoftWindows8.1;printf(此电脑的版本为:%s\n,vname.c_str());return;}if(dwMajor==10&&dwMinor==0)//win10{vname=MicrosoftWindows10;printf(此电脑的版本为:%s\n,vname.c_str());return;}//下面判断不能WinServer,因为本人还未有这种系统的机子,暂时不给出//判断win8.1以下的版本SYSTEM_INFOinfo;//用SYSTEM_INFO结构判断64位AMD处理器GetSystemInfo(&info);//调用GetSystemInfo函数填充结构OSVERSIONINFOEXos;os.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);#pragmawarning(disable:4996)if(GetVersionEx((OSVERSIONINFO*)&os)){//下面根据版本信息判断操作系统名称switch(os.dwMajorVersion){//判断主版本号case4:switch(os.dwMinorVersion){//判断次版本号case0:if(os.dwPlatformId==VER_PLATFORM_WIN32_NT)vname=MicrosoftWindowsNT4.0;//1996年7月发布elseif(os.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)vname=MicrosoftWindows95;break;case10:vname=MicrosoftWindows98;break;case90:vname=MicrosoftWindowsMe;break;}break;case5:switch(os.dwMinorVersion){//再比较dwMinorVersion的值case0:vname=MicrosoftWindows2000;//1999年12月发布break;case1:vname=MicrosoftWindowsXP;//2001年8月发布break;case2:if(os.wProductType==VER_NT_WORKSTATION&&info.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)vname=MicrosoftWindowsXPProfessionalx64Edition;elseif(GetSystemMetrics(SM_SERVERR2)==0)vname=MicrosoftWindowsServer2003;//2003年3月发布elseif(GetSystemMetrics(SM_SERVERR2)!=0)vname=MicrosoftWindowsServer2003R2;break;}break;case6:switch(os.dwMinorVersion){case0:if(os.wProductType==VER_NT_WORKSTATION)vname=MicrosoftWindowsVista;elsevname=MicrosoftWindowsServer2008;//服务器版本break;case1:if(os.wProductType==VER_NT_WORKSTATION)vname=MicrosoftWindows7;elsevname=MicrosoftWindowsServer2008R2;break;case2:if(os.wProductType==VER_NT_WORKSTATION)vname=MicrosoftWindows8;elsevname=MicrosoftWindowsServer2012;break;}break;default:vname=未知操作系统;}printf(此电脑的版本为:%s\n,vname.c_str());}elseprintf(版本获取失败\n);}intmain(){getSystemName();system(pause);return0;}
本文标题:判断操作系统的c++源代码
链接地址:https://www.777doc.com/doc-1414087 .html