C++ (Qt)// Mac OS XQByteArray getOsXInfo(){ QProcess proc; // Mac OS X proc.start("sw_vers", QStringList() << "-productName", QProcess::ReadOnly); proc.waitForFinished(); QByteArray result = proc.readAllStandardOutput().trimmed() + " "; // 10.8.4 proc.start("sw_vers", QStringList() << "-productVersion", QProcess::ReadOnly); proc.waitForFinished(); result += proc.readAllStandardOutput().trimmed() + " "; // x86_64 i386 proc.start("uname", QStringList() << "-m" << "-p", QProcess::ReadOnly); proc.waitForFinished(); result += proc.readAllStandardOutput().trimmed(); return result;}
C++ (Qt)// Windows#include <sstream> // WinXP toolchain doesn't define consts below#ifndef PRODUCT_CORE_N#define PRODUCT_CORE_N 0x00000062#endif#ifndef PRODUCT_CORE_COUNTRYSPECIFIC#define PRODUCT_CORE_COUNTRYSPECIFIC 0x00000063#endif#ifndef PRODUCT_PROFESSIONAL_WMC#define PRODUCT_PROFESSIONAL_WMC 0x00000067#endif typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); // GetNativeSystemInfo()typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); // GetProductInfo() QByteArray getWinInfo(){ // credits: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx (Getting the System Version) OSVERSIONINFOEX osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); BOOL bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi); if (!bOsVersionInfoEx || VER_PLATFORM_WIN32_NT != osvi.dwPlatformId || osvi.dwMajorVersion < 5) return QByteArray(); // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); HMODULE kernel32Handle = GetModuleHandle(L"kernel32.dll"); PGNSI pGNSI = (PGNSI)GetProcAddress(kernel32Handle, "GetNativeSystemInfo"); if (pGNSI) pGNSI(&si); else GetSystemInfo(&si); std::stringstream os; // Test for the specific product switch (osvi.dwMajorVersion) { case 6: { switch (osvi.dwMinorVersion) { case 2: os << (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 8" : "Windows Server 2012"); break; case 1: os << (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 7" : "Windows Server 2008 R2"); break; case 0: os << (osvi.wProductType == VER_NT_WORKSTATION ? "Windows Vista" : "Windows Server 2008"); break; default: os << "Windows NEW: minor " << osvi.dwMinorVersion << ", product " << osvi.wProductType; break; } os << " "; DWORD dwType; PGPI pGPI = (PGPI)GetProcAddress(kernel32Handle, "GetProductInfo"); pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); switch(dwType) { case PRODUCT_ULTIMATE: os << "Ultimate Edition"; break; case PRODUCT_PROFESSIONAL: os << "Professional"; break; case PRODUCT_PROFESSIONAL_N: os << "Professional N"; break; case PRODUCT_HOME_PREMIUM: os << "Home Premium Edition"; break; case PRODUCT_HOME_BASIC: os << "Home Basic Edition"; break; case PRODUCT_ENTERPRISE: os << "Enterprise Edition"; break; case PRODUCT_BUSINESS: os << "Business Edition"; break; case PRODUCT_STARTER: os << "Starter Edition"; break; case PRODUCT_STARTER_N: os << "Starter N Edition"; break; case PRODUCT_CLUSTER_SERVER: os << "Cluster Server Edition"; break; case PRODUCT_DATACENTER_SERVER: os << "Datacenter Edition"; break; case PRODUCT_DATACENTER_SERVER_CORE: os << "Datacenter Edition (core installation)"; break; case PRODUCT_ENTERPRISE_SERVER: os << "Enterprise Edition"; break; case PRODUCT_ENTERPRISE_SERVER_CORE: os << "Enterprise Edition (core installation)"; break; case PRODUCT_ENTERPRISE_SERVER_IA64: os << "Enterprise Edition for Itanium-based Systems"; break; case PRODUCT_SMALLBUSINESS_SERVER: os << "Small Business Server"; break; case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: os << "Small Business Server Premium Edition"; break; case PRODUCT_STANDARD_SERVER: os << "Standard Edition"; break; case PRODUCT_STANDARD_SERVER_CORE: os << "Standard Edition (core installation)"; break; case PRODUCT_WEB_SERVER: os << "Web Server Edition"; break; case PRODUCT_PROFESSIONAL_WMC: os << "Professional with Media Center"; break; case PRODUCT_CORE_N: // Windows 8 N os << "N"; break; case PRODUCT_CORE_COUNTRYSPECIFIC: os << "China"; break; default: os << "dwType " << dwType; break; } } break; case 5: switch (osvi.dwMinorVersion) { case 2: if (GetSystemMetrics(SM_SERVERR2)) os << "Windows Server 2003 R2, "; else if (osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER) os << "Windows Storage Server 2003"; else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER) os << "Windows Home Server"; else if(osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) os << "Windows XP Professional x64 Edition"; else os << "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) os << "Datacenter Edition for Itanium-based Systems"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) os << "Enterprise Edition for Itanium-based Systems"; } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) os << "Datacenter x64 Edition"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) os << "Enterprise x64 Edition"; else os << "Standard x64 Edition"; } else { if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER) os << "Compute Cluster Edition"; else if (osvi.wSuiteMask & VER_SUITE_DATACENTER) os << "Datacenter Edition"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) os << "Enterprise Edition"; else if (osvi.wSuiteMask & VER_SUITE_BLADE) os << "Web Edition"; else os << "Standard Edition"; } } break; case 1: os << "Windows XP " << (osvi.wSuiteMask & VER_SUITE_PERSONAL ? "Home Edition" : "Professional"); break; case 0: os << "Windows 2000 "; if (osvi.wProductType == VER_NT_WORKSTATION) os << "Professional"; else { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) os << "Datacenter Server"; else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) os << "Advanced Server"; else os << "Server"; } break; } break; default: os << "Windows SUPERNEW: major " << osvi.dwMajorVersion << ", minor " << osvi.dwMinorVersion << ", product " << osvi.wProductType; break; } // Include service pack (if any) and build number// if (wcslen(osvi.szCSDVersion) > 0)// os << " " << osvi.szCSDVersion;// os << " (build " << osvi.dwBuildNumber << ")"; if (osvi.dwMajorVersion >= 6) { if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) os << ", 64-bit"; else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) os << ", 32-bit"; } return os.str().c_str();}