C++查询中文名称的操作系统版本:
看网上没有例子,这里放出来两个版本的.
代码如下:
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毫秒吧。