RTSystemQueryOSInfo-win.cpp revision 51df2768ddb5c4dd975267b4ba82ba02da82d20a
/* $Id$ */
/** @file
* IPRT - RTSystemQueryOSInfo, generic stub.
*/
/*
* Copyright (C) 2008-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <Windows.h>
#include <WinUser.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Windows OS type as determined by rtSystemWinOSType().
*/
typedef enum RTWINOSTYPE
{
kRTWinOSType_UNKNOWN = 0,
kRTWinOSType_9XFIRST = 1,
kRTWinOSType_9XLAST = 99,
kRTWinOSType_NTFIRST = 100,
kRTWinOSType_NT_UNKNOWN = 199,
} RTWINOSTYPE;
/**
* These are the PRODUCT_* defines found in the Vista Platform SDK and returned
* by GetProductInfo().
*
* We define them ourselves because we don't necessarily have any Vista PSDK around.
*/
typedef enum RTWINPRODTYPE
{
kRTWinProdType_DATACENTER_SERVER_CORE = 0x0000000C, ///< Server Datacenter Edition (core installation)
kRTWinProdType_ENTERPRISE_SERVER_CORE = 0x0000000E, ///< Server Enterprise Edition (core installation)
kRTWinProdType_ENTERPRISE_SERVER_IA64 = 0x0000000F, ///< Server Enterprise Edition for Itanium-based Systems
kRTWinProdType_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019, ///< Small Business Server Premium Edition
/**
* Translates OSVERSIONINOFEX into a Windows OS type.
*
* @returns The Windows OS type.
* @param pOSInfoEx The OS info returned by Windows.
*
* @remarks This table has been assembled from Usenet postings, personal
* observations, and reading other people's code. Please feel
* free to add to it or correct it.
* <pre>
dwPlatFormID dwMajorVersion dwMinorVersion dwBuildNumber
95 1 4 0 950
95 SP1 1 4 0 >950 && <=1080
95 OSR2 1 4 <10 >1080
98 1 4 10 1998
98 SP1 1 4 10 >1998 && <2183
98 SE 1 4 10 >=2183
ME 1 4 90 3000
NT 3.51 2 3 51 1057
NT 4 2 4 0 1381
2000 2 5 0 2195
XP 2 5 1 2600
2003 2 5 2 3790
Vista 2 6 0
CE 1.0 3 1 0
CE 2.0 3 2 0
CE 2.1 3 2 1
CE 3.0 3 3 0
</pre>
*/
{
&& dwMajorVersion == 4)
{
if ( dwMinorVersion < 10
&& dwBuildNumber == 950)
else if ( dwMinorVersion < 10
&& dwBuildNumber > 950
&& dwBuildNumber <= 1080)
else if ( dwMinorVersion < 10
&& dwBuildNumber > 1080)
else if ( dwMinorVersion == 10
&& dwBuildNumber == 1998)
else if ( dwMinorVersion == 10
&& dwBuildNumber > 1998
&& dwBuildNumber < 2183)
else if ( dwMinorVersion == 10
&& dwBuildNumber >= 2183)
else if (dwMinorVersion == 90)
}
else if (dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if ( dwMajorVersion == 3
&& dwMinorVersion == 51)
else if ( dwMajorVersion == 4
&& dwMinorVersion == 0)
else if ( dwMajorVersion == 5
&& dwMinorVersion == 0)
else if ( dwMajorVersion == 5
&& dwMinorVersion == 1)
else if ( dwMajorVersion == 5
&& dwMinorVersion == 2)
else if ( dwMajorVersion == 6
&& dwMinorVersion == 0)
{
if (bProductType != VER_NT_WORKSTATION)
else
}
else if ( dwMajorVersion == 6
&& dwMinorVersion == 1)
else if ( dwMajorVersion == 6
&& dwMinorVersion == 2)
else
}
return enmVer;
}
/**
* Wrapper around the GetProductInfo API.
*
* @returns The vista type.
*/
static RTWINPRODTYPE rtSystemWinGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion)
{
pfnGetProductInfo = (BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo");
if (pfnGetProductInfo)
{
if (pfnGetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, &dwProductType))
return (RTWINPRODTYPE)dwProductType;
}
return kRTWinProdType_UNDEFINED;
}
/**
* Appends the product type if available.
*
* @param pszTmp The buffer. Assumes it's big enough.
*/
static void rtSystemWinAppendProductType(char *pszTmp)
{
switch (enmVistaType)
{
case kRTWinProdType_DATACENTER_SERVER: strcat(pszTmp, " Server Datacenter Edition (full installation)"); break;
case kRTWinProdType_DATACENTER_SERVER_CORE: strcat(pszTmp, " Server Datacenter Edition (core installation)"); break;
case kRTWinProdType_ENTERPRISE_SERVER: strcat(pszTmp, " Server Enterprise Edition (full installation)"); break;
case kRTWinProdType_ENTERPRISE_SERVER_CORE: strcat(pszTmp, " Server Enterprise Edition (core installation)"); break;
case kRTWinProdType_ENTERPRISE_SERVER_IA64: strcat(pszTmp, " Server Enterprise Edition for Itanium-based Systems"); break;
case kRTWinProdType_SERVER_FOR_SMALLBUSINESS: strcat(pszTmp, " Server for Small Business Edition"); break;
case kRTWinProdType_SMALLBUSINESS_SERVER_PREMIUM: strcat(pszTmp, " Small Business Server Premium Edition"); break;
case kRTWinProdType_STANDARD_SERVER: strcat(pszTmp, " Server Standard Edition (full installation)"); break;
case kRTWinProdType_STANDARD_SERVER_CORE: strcat(pszTmp, " Server Standard Edition (core installation)"); break;
case kRTWinProdType_STORAGE_ENTERPRISE_SERVER: strcat(pszTmp, " Storage Server Enterprise Edition"); break;
case kRTWinProdType_STORAGE_EXPRESS_SERVER: strcat(pszTmp, " Storage Server Express Edition"); break;
case kRTWinProdType_STORAGE_STANDARD_SERVER: strcat(pszTmp, " Storage Server Standard Edition"); break;
case kRTWinProdType_STORAGE_WORKGROUP_SERVER: strcat(pszTmp, " Storage Server Workgroup Edition"); break;
case kRTWinProdType_WEB_SERVER_CORE: strcat(pszTmp, " Web Server Edition (core installation)"); break;
case kRTWinProdType_UNDEFINED: break;
}
}
/**
* Services the RTSYSOSINFO_PRODUCT, RTSYSOSINFO_RELEASE
* and RTSYSOSINFO_SERVICE_PACK requests.
*
* @returns See RTSystemQueryOSInfo.
* @param enmInfo See RTSystemQueryOSInfo.
* @param pszInfo See RTSystemQueryOSInfo.
* @param cchInfo See RTSystemQueryOSInfo.
*/
{
int rc;
/*
* Make sure it's terminated correctly in case of error.
*/
*pszInfo = '\0';
/*
* Query the Windows version.
*
* ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe).
*/
{
}
/* Get extended version info for 2000 and later. */
{
{
}
}
/*
* Service the request.
*/
char szTmp[512];
szTmp[0] = '\0';
rc = VINF_SUCCESS;
switch (enmInfo)
{
/*
* The product name.
*/
case RTSYSOSINFO_PRODUCT:
{
switch (enmVer)
{
case kRTWinOSType_XP:
#if 0 /** @todo fixme */
#endif
break;
case kRTWinOSType_VISTA:
{
break;
}
case kRTWinOSType_NT_UNKNOWN:
RTStrPrintf(szTmp, sizeof(szTmp), "Unknown NT v%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion);
break;
default:
AssertFailed();
case kRTWinOSType_UNKNOWN:
RTStrPrintf(szTmp, sizeof(szTmp), "Unknown %d v%u.%u", OSInfoEx.dwPlatformId, OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion);
break;
}
break;
}
/*
* The release.
*/
case RTSYSOSINFO_RELEASE:
{
RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion, OSInfoEx.dwBuildNumber);
break;
}
/*
* Get the service pack.
*/
case RTSYSOSINFO_SERVICE_PACK:
{
{
RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u", (unsigned)OSInfoEx.wServicePackMajor, (unsigned)OSInfoEx.wServicePackMinor);
else
}
else if (OSInfoEx.szCSDVersion[0])
{
/* just copy the entire string. */
}
else
{
switch (enmVer)
{
default:
break;
}
}
break;
}
default:
}
/*
* Copy the result to the return buffer.
*/
else
{
if (RT_SUCCESS(rc))
}
return VINF_SUCCESS;
}
{
/*
* Quick validation.
*/
if (!cchInfo)
return VERR_BUFFER_OVERFLOW;
/*
* Handle the request.
*/
switch (enmInfo)
{
case RTSYSOSINFO_PRODUCT:
case RTSYSOSINFO_RELEASE:
case RTSYSOSINFO_SERVICE_PACK:
case RTSYSOSINFO_VERSION:
default:
*pszInfo = '\0';
return VERR_NOT_SUPPORTED;
}
}