1. 了解Windows作業系統版本的號碼 : Operating System Version
2. 針對Windows8以上版本,需要使用: Version Helper functions
3. 針對Windows8以下版本,需要使用: GetVersionExA function
//---------------------------------------------------------------------------
AnsiString GetSystemName()
{
AnsiString Name=""; //先判斷是否為win8.1或win10
typedef void(__stdcall*NTPROC)(DWORD*, DWORD*, DWORD*);
HINSTANCE hinst=LoadLibrary("ntdll.dll");
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC proc=(NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
proc(&dwMajor, &dwMinor, &dwBuildNumber);
dwBuildNumber&=0xffff;
if(dwMajor==6 && dwMinor==3) //win 8.1
{
Name="Microsoft Windows 8.1";
}
else if(dwMajor==10 && dwMinor==0) //win 10
{
Name="Microsoft Windows 10";
}
else
{
//判斷win8.1以下的版本
SYSTEM_INFO info; //用SYSTEM_INFO結構判斷64位AMD處理器
GetSystemInfo(&info); //呼叫GetSystemInfo函式填充結構
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);
#pragma warning(disable:4996)
if(GetVersionEx((OSVERSIONINFO *)&os))
{ //下面根據版本資訊判斷作業系統名稱
switch (os.dwMajorVersion)
{ //判斷主版本號
case 4:
switch (os.dwMinorVersion)
{
case 0:
if(os.dwPlatformId==VER_PLATFORM_WIN32_NT)
Name="Microsoft Windows NT 4.0";
else if(os.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
Name="Microsoft Windows 95";
break;
case 10:
Name="Microsoft Windows 98";
break;
case 90:
Name="Microsoft Windows Me";
break;
}
break;
case 5:
switch(os.dwMinorVersion)
{
case 0:
Name="Microsoft Windows 2000";
break;
case 1:
Name="Microsoft Windows XP";
break;
case 2:
if(os.wProductType==VER_NT_WORKSTATION && info.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
Name="Microsoft Windows XP Professional x64 Edition";
else
Name="Microsoft Windows Server 2003";
}
break;
case 6:
switch(os.dwMinorVersion)
{
case 0:
if(os.wProductType==VER_NT_WORKSTATION)
Name="Microsoft Windows Vista";
else
Name="Microsoft Windows Server 2008";
break;
case 1:
if(os.wProductType==VER_NT_WORKSTATION)
Name="Microsoft Windows 7";
else
Name="Microsoft Windows Server 2008 R2";
break;
case 2:
if(os.wProductType==VER_NT_WORKSTATION)
Name="Microsoft Windows 8";
else
Name="Microsoft Windows Server 2012";
break;
}
break;
}
}
}
return Name;
}
//---------------------------------------------------------------------------