QT獲取作業系統版本
static QString GetSysVersion() { DWORD dwVersion = 0; WKSTA_INFO_100 *wkstaInfo = NULL;
NET_API_STATUS netStatus = NetWkstaGetInfo(NULL, 100, (BYTE **)&wkstaInfo); if (netStatus == NERR_Success) { DWORD dwMajVer = wkstaInfo->wki100_ver_major; DWORD dwMinVer = wkstaInfo->wki100_ver_minor; dwVersion = (DWORD)MAKELONG(dwMinVer, dwMajVer); NetApiBufferFree(wkstaInfo); }
char buf[128]; sprintf(buf, "%d.%d", (dwVersion >> 16) & 0xffff, (dwVersion >> 0) & 0xffff);
QString version = QString::fromLocal8Bit(buf); return version; }
QString systemVersion() { static QString verName = ""; if (!verName.isEmpty()) { return verName; }
#ifdef Q_OS_WIN QString version = GetSysVersion();
if (version.startsWith("5.1")) { verName = "Windows XP"; } else if (version.startsWith("5.2")) { verName = "Windows XP 64-Bit Edition"; } else if (version.startsWith("6.0")) { verName = "Windows Vista"; } else if (version.startsWith("6.1")) { verName = "Windows 7"; } else if (version.startsWith("6.2")) { verName = "Windows 8"; } else if (version.startsWith("6.3")) { verName = "Windows 8.1"; } else if (version.startsWith("10.0")) { verName = "Windows 10"; } else { verName = "Windows-Unknown"; } #endif return verName; }