Link to home
Start Free TrialLog in
Avatar of perkley
perkley

asked on

How to read if Win2000 or Win95/98?

I currently use this code to show the information for Windows 95 and 98.

var
  Reg: TRegistry;

begin
  Reg := TRegistry.Create;

  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', FALSE)
  then lblOSVersion.Caption := Reg.ReadString('Version') +' (Build: '+Reg.ReadString('VersionNumber')+')';
  Reg.Free;

This works great, unfortunately I do not have Windows NT or 2000 to play around with to make it work on those platforms.  I have tried my program on those systems, and when I visit the about box, nothing comes up for the Platform.

What do I need to do to get it to display Windows 2000 or Windows NT or Win95 and Win98 depending on what machine they are on?
Avatar of inthe
inthe

procedure TForm1.Button1Click(Sender: TObject);
var
OS : TOSVersionInfo;
begin
OS.dwOSVersionInfoSize := sizeof(OS);
GetVersionEx(OS);
with OS do
    case dwPlatformId of
        VER_PLATFORM_WIN32s :
              label1.caption := 'Windows 3.1x/32s';
        VER_PLATFORM_WIN32_WINDOWS :
            Begin
                if (dwMajorVersion = 4) and (dwMinorVersion > 0) then begin
               label1.caption := 'Windows 98';
               label2.caption := inttostr(dwMajorVersion);
               label3.caption := inttostr(dwMinorVersion);
               label4.caption := inttostr(dwPlatformID);
               label5.caption := inttostr(loword(dwBuildNumber));
               label6.caption := os.szCSDVersion;
                end
              else
                label1.caption := 'Windows 95';
            end;
        VER_PLATFORM_WIN32_NT :

          label1.caption := 'Windows NT' ;
      end;
  end;

i suspect this next part may not format on e.e corrctly but it is list of most major/minor versions to check for in your function

            Win95      Win3.11      Win98      Win98SE      Winnt3.51      Winnt4.0      Win2000      Winnt5

dwPlatFormID              1      1      1      1      2      2            

dwMajorVersion             4            4      4      3      4      5      5

dwMinorVersion            0            10      10      51      0      0      
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ps,
ignore winnt5 and the last 5 in dwminorversion..
listen
Avatar of perkley

ASKER

Thank you very much, it worked well, except that when I tried it on a Win2000 machine it said it was Windows NT.

The Win2000 had a dwMinorVersion = 0, so your function that you mentioned above worked except that I had to change it to = 0, not > 0.