流水- 代码来自: MSDN
#include <windows.h>
#include <stdio.h>
#define BUFSIZE 80
BOOL GetOSVer(char *szOSName);
int main()
{
char szname[MAX_PATH];
memset(szname,0,MAX_PATH);
BOOL bRet = GetOSVer(szname);
printf("Your Os version is %s\n ",szname);
return 0;
}
BOOL GetOSVer(char *szname)
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
return FALSE;
}
switch (osvi.dwPlatformId)
{
// Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:
// Test for the specific product family.
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
strcpy(szname,"Microsoft Windows Server 2003 family, ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
strcpy(szname,"Microsoft Windows XP ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
strcpy(szname,"Microsoft Windows 2000 ");
if ( osvi.dwMajorVersion <= 4 )
strcpy(szname,"Microsoft Windows NT ");
// Test for specific product on Windows NT 4.0 SP6 and later.
if( bOsVersionInfoEx )
{
// Test for the workstation type.
if ( osvi.wProductType == VER_NT_WORKSTATION )
{
if( osvi.dwMajorVersion == 4 )
strcat(szname, "Workstation 4.0 " );
else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
strcat(szname, "Home Edition " );
else
strcat(szname, "Professional " );
}
// Test for the server type.
else if ( osvi.wProductType == VER_NT_SERVER )
{
if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strcat(szname, "Datacenter Edition " );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
&nbs