Get OS Version

Get OS Version

取得 Windows 作業系統版本


{
   OSVERSIONINFO vInfo;
 
   ZeroMemory(&vInfo, sizeof(OSVERSIONINFO));
 
   vInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
   String S_os;
   String S_majorv;
   String S_minorv;
   String S_build;
   String OS_type;
 
   if (GetVersionEx(&vInfo))
   {
      S_os = "Microsoft Windows ";
 
      switch (vInfo.dwPlatformId)
      {
         case VER_PLATFORM_WIN32s :
              S_os += "3.1";
              OS_type = "3.1";
              break;
 
         case VER_PLATFORM_WIN32_WINDOWS :
            if (vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 0)
            {
               S_os += "95 ";
               if (vInfo.szCSDVersion[1] == 'C')
               {
                  S_os += "OSR2";
                  OS_type =  "OSR2";
                  break;
               }
            }
            if (vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 10)
            {
               S_os += "98";
               if (vInfo.szCSDVersion[1] == 'A')
               {
                  S_os += "SE";
                  OS_type =  "SE";
                  break;
               }
            }
 
            if (vInfo.dwMajorVersion == 4 && vInfo.dwMinorVersion == 90)
            {
               S_os += "ME";
               OS_type =  "ME";
               break;
            }
 
         case VER_PLATFORM_WIN32_NT :
            if (vInfo.dwMajorVersion == 3)
            {
                S_os += "NT 3.51";
                OS_type =  "NT 3.51";
                break;
            }
            if (vInfo.dwMajorVersion == 4)
            {
               S_os += "NT 4.0";
               OS_type =  "NT 4.0";
               break;
            }
            if (vInfo.dwMajorVersion == 5 && vInfo.dwMinorVersion == 0)
            {
               S_os += "2000";
               OS_type =  "2000";
               break;
            }
            if (vInfo.dwMajorVersion == 5 && vInfo.dwMinorVersion == 1)
            {
               S_os += "XP";
               OS_type =  "XP";
               break;
            }
      }
   }
 
   if ( display_info )
   {
       S_majorv = FormatFloat("0",(double)vInfo.dwMajorVersion);
       S_minorv = FormatFloat("0",(double)vInfo.dwMinorVersion); 
       S_build    = FormatFloat("0",(double)vInfo.dwBuildNumber);
 
       ShowMessage( S_os
                    + "\n" + "Version " + S_majorv + "." + S_minorv
                    + " \n" + "Build  "
                    + S_build);
   }
   return OS_type;
}

 

Dotblogs 的標籤: