C++ Windows查询操作系统版本名称,例如(旗舰版、标准版、专业版)
1.Windows下打开指定目录并定位到具体文件2.C++实现Windows释放资源文件到本地3.Windows U盘管控方案4.Windows下Cmake编译Poco库
5.C++ Windows查询操作系统版本名称,例如(旗舰版、标准版、专业版)
C++查询中文名称的操作系统版本:
看网上没有例子,这里放出来两个版本的.
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | std::string ExecCommand( const char * cmd) { CHAR buf[128]; std::string result = "" ; FILE * pipe = _popen(cmd, "r" ); if (pipe) { while ( fgets (buf, sizeof (buf), pipe) != NULL) { result += buf; } _pclose(pipe); } return result; } int 获取操作系统中文版本() { DWORD productType; if (GetProductInfo(6, 1, 0, 0, &productType)) { if (productType == PRODUCT_ULTIMATE) { std::cout << "Windows 7 旗舰版" << std::endl; } else if (productType == PRODUCT_HOME_BASIC) { std::cout << "Windows 7 家庭版" << std::endl; } else if (productType == PRODUCT_HOME_PREMIUM) { std::cout << "Windows 7 家庭高级版" << std::endl; } else if (productType == PRODUCT_PROFESSIONAL) { std::cout << "Windows 10 专业版" << std::endl; } else { std::cout << "继续添加宏定义判断更多版本吧" << std::endl; } } else { std::cerr << "无法获取产品信息" << std::endl; } std::string cmdRet = ExecCommand( "wmic os get Caption" ); std::cout << cmdRet.c_str() << std::endl; } |
Ps:第二种可能会稍慢0.0000001毫秒吧。
合集:
业务开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步