Determine the Windows version where your application is running on  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 18/01/00

Tip accessed 471 times

 


We will use the Api funtion GetVersionEx

Put this in the OnClick of a TButton:


 procedure TForm1.Button1Click(Sender: TObject);

   function QueWindows:String;
   var
      Version:TOsVersionInfo;
   begin
     Version.dwOSVersionInfoSize:=SizeOf(Version);
     GetVersionex(Version);
     Case Version.dwPlatformId of
       VER_PLATFORM_WIN32s:
         Result:='Win311';
       VER_PLATFORM_WIN32_WINDOWS:
         Result:='Win9X';
       VER_PLATFORM_WIN32_NT:
           Result:='WinNT';
     end;
   end;
 begin
   Form1.Caption:=QueWindows;
 end;





Without reinventing the weel... O:)


Simply use the Delphi variable 'Win32Platform'

Example:

  • Add 'SysUtils' in the uses of your form


     procedure TForm1.Button1Click(Sender: TObject);
    
       function QueWindows:string;
       begin
         case Win32Platform of
           VER_PLATFORM_WIN32s:
             Result:='Win311';
           VER_PLATFORM_WIN32_WINDOWS:
             Result:='Win9X';
           VER_PLATFORM_WIN32_NT:
               Result:='WinNT';
         end;
       end;
    
     begin
       Caption:=QueWindows;
     end;
    




    Update send by :Jose A. García (PICKMIX@teleline.es)

    This tip wil better if we use the platform version:


     procedure TForm1.Button1Click(Sender: TObject);
     function QueWindows:string;
      var Plataforma:string;
          Version:integer;
       begin
         Version:=0;
         case Win32Platform of
           VER_PLATFORM_WIN32s:
             begin
               Result:='Plataforma: Win311 Versión: ' +
               IntTostr(Win32MajorVersion)+'.' +
               IntToStr(Win32MinorVersion);
               exit;
             end;
           VER_PLATFORM_WIN32_WINDOWS:
            begin
             Plataforma:='Plataforma: Win9X Versión: ';
             Version:=Win32BuildNumber and $0000FFFF;
            end;
           VER_PLATFORM_WIN32_NT:
            begin
             Plataforma:='Plataforma: WinNT Versión: ';
             Version:=Win32BuildNumber;
            end;
         end;
    
           if Win32CSDVersion = '' then
             Result:= Plataforma+IntTostr( Win32MajorVersion)+
                      '.'+
                      IntTostr( Win32MinorVersion)+
                      '.'+
                      IntTostr(Version)
            else
             Result:= Plataforma+IntTostr( Win32MajorVersion)+
                      '.'+
                      IntTostr( Win32MinorVersion)+
                      '.'+
                      IntTostr(Version)+
                      ' '+
                      Win32CSDVersion;
       end;
     begin
       Caption:=QueWindows;
     end;
    






    Updated at 20/11/99
    Due to reinventing the weel...


    Updated at 18/01/2000
    Due to the comments of Jose A. García