Home > Delphi > What version of windows is running?

What version of windows is running?

October 14, 2013 Leave a comment Go to comments

This simple function checks the current platform and recognized the most commonly used platforms: Windows XP, Windows Vista and Windows 7. It also recognized older systems like Windows 95/98/me and NT. And it should be easy enough to expand it to recognize windows 8 as well.

Notes

There are some radical differences between Windows XP (which is my favorite platform by the way) and Windows 7. Most notoriously is the changes in security and data storage. There are operations you can do under Windows XP that you can not (or should not) do under Windows 7. The following code simplifies the task of creating code that works on all 3 platforms (and older).

Type
TJLWinOSType = (otUnknown,otWin95,otWin98,otWinME,otWinNT,otWin2000,otWinXP,otVista,otWin7);

Function JL_GetOSType(out Value:TJLWinOSType):Boolean;
var
  FInfo: TOSVersionInfoA;
begin
  (* default to unknown *)
  Value:=otUnknown;

  (* prepare version-info call *)
  fillchar(FInfo,SizeOf(FInfo),#0);
  FInfo.dwOSVersionInfoSize:=sizeof(FInfo);

  (* Call OS to get info *)
  result:=GetVersionExA(FInfo);
  If result then
  Begin
    Case FInfo.dwPlatformId of
    VER_PLATFORM_WIN32_NT:
      Begin
        if FInfo.dwMajorVersion <= 4 then
        Value:=otWinNT else

        if (FInfo.dwMajorVersion = 5)
        and (FInfo.dwMinorVersion = 0) then
        Value:=otWin2000 else

        if (FInfo.dwMajorVersion = 5)
        and (FInfo.dwMinorVersion = 1) then
        Value:=otWinXP else

        if (FInfo.dwMajorVersion = 6)
        and (FInfo.dwMinorVersion=0) then
        Value:=otVista;
      end;
    VER_PLATFORM_WIN32_WINDOWS:
      Begin
       if (FInfo.dwMajorVersion = 4)
       and (FInfo.dwMinorVersion = 0) then
       Value:=otWin95 else

       if (FInfo.dwMajorVersion = 4)
       and (FInfo.dwMinorVersion = 10) then
       Value:=otWin98 else

       if (FInfo.dwMajorVersion = 4)
       and (FInfo.dwMinorVersion = 90) then
       Value:=otWinME;
      end;
    end;
  End;
End;
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: