void GetOperatingSystemInfo()

in host/common/hostagenthelpers.cpp [3451:3636]


void GetOperatingSystemInfo(std::string& strInfo)
{
    std::string osinfo("");
    //taken from MSDN code
    OSVERSIONINFOEX osvi;
    BOOL bOsVersionInfoEx;
    char tmpbuf[80];
    memset(tmpbuf,0,80);

   // 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;
   }

   switch (osvi.dwPlatformId)
   {
      // Test for the Windows NT product family.
      case VER_PLATFORM_WIN32_NT:

      // Test for the specific product.
      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
         osinfo += "Microsoft Windows Server 2003 ";

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
         osinfo += "Microsoft Windows XP ";

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
         osinfo += "Microsoft Windows 2000 ";

      if ( osvi.dwMajorVersion <= 4 )
         osinfo += "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 )
               osinfo +=  "Workstation 4.0 " ;
            else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
               osinfo +=  "Home Edition " ;
            else osinfo +=  "Professional " ;
         }
            
         // Test for the server type.
         else if ( osvi.wProductType == VER_NT_SERVER || 
                   osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
         {
            if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
            {
               if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                  osinfo +=  "Datacenter Edition " ;
               else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                  osinfo +=  "Enterprise Edition " ;
               else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
                  osinfo +=  "Web Edition " ;
               else osinfo +=  "Standard Edition " ;
            }
            else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
            {
               if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                  osinfo +=  "Datacenter Server " ;
               else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                  osinfo +=  "Advanced Server " ;
               else osinfo +=  "Server " ;
            }
            else  // Windows NT 4.0 
            {
               if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                  osinfo += "Server 4.0, Enterprise Edition " ;
               else osinfo +=  "Server 4.0 " ;
            }
         }
      }
      // Test for specific product on Windows NT 4.0 SP5 and earlier
      else  
      {
         HKEY hKey;
         char szProductType[BUFSIZE];
         DWORD dwBufLen=BUFSIZE;
         LONG lRet;

         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
            "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
            0, KEY_QUERY_VALUE, &hKey );
         if( lRet != ERROR_SUCCESS )
            return ;

         lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
            (LPBYTE) szProductType, &dwBufLen);
         if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
            return;

         RegCloseKey( hKey );

         if ( lstrcmpi( "WINNT", szProductType) == 0 )
            osinfo +=  "Workstation " ;
         if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
            osinfo += "Server " ;
         if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
            osinfo += "Advanced Server " ;
         inm_sprintf_s(tmpbuf, ARRAYSIZE(tmpbuf), "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
         osinfo += tmpbuf;         
      }

      // Display service pack (if any) and build number.

      if( osvi.dwMajorVersion == 4 && 
          lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
      { 
         HKEY hKey;
         LONG lRet;

         // Test for SP6 versus SP6a.
         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
            0, KEY_QUERY_VALUE, &hKey );
         if( lRet == ERROR_SUCCESS )
         {
            memset(tmpbuf, 0, sizeof(tmpbuf));
            inm_sprintf_s(tmpbuf, ARRAYSIZE(tmpbuf), "Service Pack 6a (Build %d)",
            osvi.dwBuildNumber & 0xFFFF );    
            osinfo += tmpbuf;        
         }
         else // Windows NT 4.0 prior to SP6a
         {
             memset(tmpbuf, 0, sizeof(tmpbuf));
             inm_sprintf_s(tmpbuf, ARRAYSIZE(tmpbuf), "%s (Build %d)\n",
               osvi.szCSDVersion,
               osvi.dwBuildNumber & 0xFFFF);
            osinfo += tmpbuf;
         }

         RegCloseKey( hKey );
      }
      else // not Windows NT 4.0 
      {
          memset(tmpbuf, 0, sizeof(tmpbuf));
          inm_sprintf_s(tmpbuf, ARRAYSIZE(tmpbuf), "%s (Build %d)\n",
            osvi.szCSDVersion,
            osvi.dwBuildNumber & 0xFFFF);
         osinfo += tmpbuf;
      }

      break;

      // Test for the Windows Me/98/95.
      case VER_PLATFORM_WIN32_WINDOWS:

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
      {
          osinfo += "Microsoft Windows 95 ";
          if (osvi.szCSDVersion[1]=='C' || osvi.szCSDVersion[1]=='B')
             osinfo += "OSR2 " ;
      } 

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
      {
          osinfo += "Microsoft Windows 98 ";
          if ( osvi.szCSDVersion[1] == 'A' )
             osinfo += "SE ";
      } 

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
      {
          osinfo += "Microsoft Windows Millennium Edition";
      } 
      break;

      case VER_PLATFORM_WIN32s:

      osinfo += "Microsoft Win32s";
      break;

    }
    strInfo = osinfo;
}