Tag Archive: windows

get windows version – 2

  MAP
    ReFlex__OS(BYTE Extended=0),BYTE
    MODULE('')
      GetVersionEx(LONG),SIGNED,PASCAL,NAME('GetVersionExA'),PROC
    END
  END
  
ReFlex__OS FUNCTION(BYTE Extended=0)
!
! If NOT "Extended"   return 0 = Win9x/ME, 1 = NT, 2 = W2K/Whistler(XP)
! If "Extended"       return 1 = Win95, 2 = Win98, 3 = NT3.51, 4 = NT4, 5 = W2K, 6 = ME, 7 = Whistler(XP)
! Returns 255 on error
!

OSVersionInfo       GROUP,PRE()
InfoSize              ULONG
MajorVersion          ULONG
MinorVersion          ULONG
BuildNumber           ULONG
PlatformID            ULONG
CSDVersion            STRING(128)
                    END

  !   OS          MajorVersion  MinorVersion  PlatformID
  ! =====================================================
  !  Win95             4             0            1
  !  Win98             4            >0            1
  !  ME                4            90            1
  !  NT3.51            3            51            2
  !  NT4               4             0            2
  !  W2K               5             0            2
  !  Whistler(XP)      5             1            2

  CODE
  CLEAR(OSVersionInfo)
  InfoSize = SIZE(OSVersionInfo)
  IF NOT GetVersionEx(ADDRESS(OSVersionInfo)) THEN RETURN(255).

  IF NOT Extended
    RETURN( CHOOSE(PlatformID = 1, 0, CHOOSE(PlatformID = 2, CHOOSE(MajorVersion < 5, 1, 2), 255)) )
  ELSE
    IF MajorVersion = 4 AND MinorVersion = 90
      RETURN(6)
    ELSIF MajorVersion = 5 AND MinorVersion = 1
      RETURN(7)
    END
    RETURN( CHOOSE(PlatformID = 1, CHOOSE(MinorVersion = 0, 1, 2), CHOOSE(PlatformID = 2, MajorVersion, 255)) )
  END

get windows version – 1

prototype:  api-function: GetVersionEx( *group), bool, pascal, raw, name('GetVersionExA')
procedure:  GetWinVersion(), long
return:     0-error, 1-win32s, 2-win95, 3-win98, 4-nt4, 5-nt2000

code: 
 execute 1+ GetWinVersion()
   s"= 'error in GetWinVersion'
   s"= 'win32s'
   s"= 'win95'
   s"= 'win98'
   s"= 'nt4'
   s"= 'nt2000'
 end
 message( s")

definition:

GetWinVersion     procedure 
ret               long, auto
tosvi             group, type
dwOSVersionInfoSize ulong
dwMajorVersion      ulong
dwMinorVersion      ulong
dwBuildNumber       ulong
dwPlatformId        ulong
szCSDVersion        cstring( 128)
                  end
osviex            group, auto
osvi                group( tosvi).
wServicePackMajor   long
wServicePackMinor   long
wSuiteMask          long
wProductType        byte
wReserved           byte
                  end
 code
 ret= 0
 clear( osviex, -1)
 osviex.osvi.dwOSVersionInfoSize= size( osviex)
 if not GetVersionEx( osviex)
   osviex.osvi.dwOSVersionInfoSize= size( osviex.osvi)
   if not GetVersionEx( osviex) then return ret.
 end
 execute 1+ osviex.osvi.dwPlatformId
   do win32s
   do win9x
   do winnt
 end
 return( ret)  

winnt routine
 if osviex.osvi.dwMajorVersion <= 4
   ret= 4
 elsif osviex.osvi.dwMajorVersion = 5
   ret= 5
 end

win9x routine
 if osviex.osvi.dwMajorVersion > 4 or |
    ( osviex.osvi.dwMajorVersion = 4 and osviex.osvi.dwMinorVersion > 
0)
   ret= 3
 else
   ret= 2
 end

win32s routine
 ret= 1

 omit( '->')
---------------------------------------------------------------------------------------------
BOOL DisplaySystemVersion()
{
   OSVERSIONINFOEX osvi;
   BOOL bOsVersionInfoEx;

   // Try calling GetVersionEx using the OSVERSIONINFOEX structure,
   // which is supported on Windows 2000.
   //
   // If that fails, try using the OSVERSIONINFO structure.

   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
   {
      // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.

      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
         return FALSE;
   }

   switch (osvi.dwPlatformId)
   {
      case VER_PLATFORM_WIN32_NT:

      // Test for the product.

         if ( osvi.dwMajorVersion <= 4 )
            printf( "Microsoft Windows NT ");

         if ( osvi.dwMajorVersion == 5 )
            printf ("Microsoft Windows 2000 ");

      // Test for workstation versus server.

         if( bOsVersionInfoEx )
         {
            if ( osvi.wProductType == VER_NT_WORKSTATION )
               printf ( "Professional " );

            if ( osvi.wProductType == VER_NT_SERVER )
               printf ( "Server " );
         }
         else
         {
            HKEY hKey;
            char szProductType[80];
            DWORD dwBufLen;

            RegOpenKeyEx( HKEY_LOCAL_MACHINE,
               "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
               0, KEY_QUERY_VALUE, &hKey );
            RegQueryValueEx( hKey, "ProductType", NULL, NULL,
               (LPBYTE) szProductType, &dwBufLen);
            RegCloseKey( hKey );
            if ( lstrcmpi( "WINNT", szProductType) == 0 )
               printf( "Workstation " );
            if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
               printf( "Server " );
         }

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

         printf ("version %d.%d %s (Build %d)\n",
            osvi.dwMajorVersion,
            osvi.dwMinorVersion,
            osvi.szCSDVersion,
            osvi.dwBuildNumber & 0xFFFF);

         break;

      case VER_PLATFORM_WIN32_WINDOWS:

         if ((osvi.dwMajorVersion > 4) || 
            ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
         {
             printf ("Microsoft Windows 98 ");
         } 
         else printf ("Microsoft Windows 95 ");

         break;

      case VER_PLATFORM_WIN32s:

         printf ("Microsoft Win32s ");
         break;
   }
   return TRUE; 
}