Link to home
Start Free TrialLog in
Avatar of ermac
ermac

asked on

Need help detecting the operating system

I need some help to detect whether the OS is Windows95 or Windows NT (which version doesn't matter)

Thanks in Advance,
Ermac


Avatar of mvz121697
mvz121697

uses
  WinProcs, SysUtils, Dialogs;

var
  Version: record
             case Boolean of
              False: (
                     Windows: record
                                 major: Byte;
                                 minor: Byte;
                               end;
                     DOS: record
                            minor: Byte;
                            major: Byte;
                          end;
                     );
              True: (GetVersion: LongInt);
            end {Version};

begin
  Version.GetVersion := GetVersion;
  if Version.Windows.major < 4 then
    ShowMessage(Format('DOS %d.%-d, Windows %d.%-d',
                       [Version.DOS.major,Version.DOS.minor,
                        Version.Windows.major,Version.Windows.minor]))
  else
    ShowMessage(Format('Windows 95/NT %d.%-d',
                       [Version.Windows.major,Version.Windows.minor]))
end.

When compiled with Delphi 1.02 and run on Windows 95, this program returns "DOS
7.0, Windows 3.95". When compiled with Delphi 2.01 and run on Windows
95, this program returns "Windows 95/NT 4.00", and so it should.
If you use Delphi 2/3 then you can use GetVersionEx:
procedure TForm1.Button1Click(Sender: TObject);
var
  FVer: TOSVERSIONINFO;
begin
  FVer.dwOSVersionInfoSize:=sizeof(TOSVERSIONINFO);
  GetVersionEx(FVer);
  if FVer.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS then
    showmessage('Windows 95 version '+InttoStr(FVer.dwMajorVersion)+'.'+InttoStr(FVer.dwMinorVersion))
  else if FVer.dwPlatformId=VER_PLATFORM_WIN32_NT then
    showmessage('Windows NT version '+InttoStr(FVer.dwMajorVersion)+'.'+InttoStr(FVer.dwMinorVersion))
end;
Avatar of ermac

ASKER

ronit..

I think your solution is much cleaner...
So how do I give you the points??

Ermac
I'll post some answer.
ASKER CERTIFIED SOLUTION
Avatar of ronit051397
ronit051397

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
Bought this Q...
So did I