// Wang Guofan 2004-04-25
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
enum Win32Type{
Win32s,
WinNT3,
Win95,
Win98,
WinME,
WinNT4,
Win2000,
WinXP
};
Win32Type IsShellType()
{
Win32Type ShellType;
DWORD winVer;
OSVERSIONINFO *osvi;
winVer=GetVersion();
if(winVer<0x80000000){ // NT
ShellType=WinNT3;
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL)
{
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==4L) ShellType=WinNT4;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L) ShellType=Win2000;
else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==1L) ShellType=WinXP;
free(osvi);
}
}
else if (LOBYTE(LOWORD(winVer))<4)
ShellType=Win32s;
else
{
ShellType=Win95;
osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
if (osvi!=NULL)
{
memset(osvi,0,sizeof(OSVERSIONINFO));
osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(osvi);
if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==10L) ShellType=Win98;
else if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==90L) ShellType=WinME;
free(osvi);
}
}
return ShellType;
}
int main()
{
int nVersion = IsShellType();
string strVersion;
switch (nVersion)
{
case 0:
strVersion = "Win32s";
break;
case 1:
strVersion = "WinNT3";
break;
case 2:
strVersion = "Win95";
break;
case 3:
strVersion = "Win98";
break;
case 4:
strVersion = "WinME";
break;
case 5:
strVersion = "WinNT4";
break;
case 6:
strVersion = "Win2000";
break;
case 7:
strVersion = "WinXP";
break;
default:
strVersion = "IUnknown";
break;
}
cout << strVersion << endl;
return 0;
}