Solved

Code For Which OS In Use

Posted on 2001-09-12
9
196 Views
Last Modified: 2010-04-06
I need the code that determines which operating system is being used.  I am using D5.

If OS is Win NT/2000 do this.

If OS is Win 95/98/ME do this.

if neither of the above do nothing.  // I can handle this one.  :)

Jeff
0
Comment
Question by:tecmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6477666
Here is what you need basicaly if you want to determine between just the NT and 9x Platforms:

procedure TForm1.Button1Click(Sender: TObject);
var
  OSVerInfo : TOSVersionInfo;
begin
  { set operating system type flag }
  OSVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  if GetVersionEx(OSVerInfo) then
  begin
    case OSVerInfo.dwPlatformId of
      VER_PLATFORM_WIN32_NT : { Windows NT/2000 }
        begin
          ShowMessage('Windows NT...');
        end;
      VER_PLATFORM_WIN32_WINDOWS :  { Windows 9x/ME }
        begin
          ShowMessage('Windows 9x...');
        end;
    else
      ShowMessage('OS Unknown.');
    end;
  end
  else
    ShowMessage('OS Unknown.');
end;

If you want to determine between seperate versions like 95, 98, 98SE, 2000, Whistler etc... then this can be done also. Just ask if you need that done.

Cheers,

Alan
0
 
LVL 4

Expert Comment

by:DMN
ID: 6477668
Here is a simple sample:

procedure TForm1.FormCreate(Sender: TObject);
var
  OSVI:OSVERSIONINFO;
begin
  OSVI.dwOSVersionInfoSize := SizeOf(OSVI);
  GetVersionEx(OSVI);
  if OSVI.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS then
    ShowMessage('Win95/98/...');
  if OSVI.dwPlatformId=VER_PLATFORM_WIN32_NT then
    ShowMessage('NT technology');
end;
0
 
LVL 4

Expert Comment

by:DMN
ID: 6477671
Oops :(
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6477767
Hello

 Here's a function will return windows version and if there's service back (if windows nt)

function GetWinVersion: String;
var
VerInfo: TOSVersionInfo;
ResultStr: string;
begin
ResultStr := '';
VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);
GetVersionEx(VerInfo);
with VerInfo do
  begin
    case dwPlatformID of
      VER_PLATFORM_WIN32S: ResultStr := ResultStr + 'Windows 3.1x running Win32s ';
      VER_PLATFORM_WIN32_WINDOWS:
        begin
          if IntToStr(dwMajorVersion) + '.' + IntToStr(dwMinorVersion) < '4.10' then
            ResultStr := ResultStr + 'Windows 95 ' + szCSDVersion + ' '
          else
            ResultStr := ResultStr + 'Windows 98 ' + szCSDVersion + ' ';
        end;
      VER_PLATFORM_WIN32_NT:
        begin
          if dwMajorVersion = 5 then
            ResultStr := ResultStr + 'Windows 2000 '
          else
            ResultStr := ResultStr + 'Windows NT ';
        end;
    end;
    ResultStr := ResultStr + IntToStr(dwMajorVersion) + '.' + IntToStr(dwMinorVersion) + ' ';
    ResultStr := ResultStr + '(Build ' +  IntToStr(LoWord(dwBuildNumber)) + ') ';
    if dwPlatformID = VER_PLATFORM_WIN32_NT then
      ResultStr := ResultStr + szCSDVersion;
  end;
Result := ResultStr;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 ShowMessage(GetWinVersion);
end;
0
 
LVL 2

Accepted Solution

by:
alexstewart@beta earned 300 total points
ID: 6477863
The Sysutils unit has a lazy way, avoiding the API. When we all go dotnet, will api calls just be excess baggage?

this from the delphi help..

var Win32Platform: Integer = 0;

Description

Win32Platform is used to identify the type of Win32 platform the system is running. This will be one of the following values:

Value     Meaning
VER_PLATFORM_WIN32s     System is Win32s.
VER_PLATFORM_WIN32_WINDOWS     System is Windows 95.
VER_PLATFORM_WIN32_NT     System is Windows NT.

I dont know what the Win32Platform equates to in Linux, you could use conditional compilation to fix it.

At compile time you can use the
{$IFDEF WINDOWS} or LINUX
and to determine the target platform. Check outthe new (in delphi 6) {$ELSEIF} directive in this regard.

as
0
 

Expert Comment

by:DelFreak
ID: 6478267
Listening...
0
 
LVL 2

Expert Comment

by:alexstewart@beta
ID: 6478282
ps you might also need the
GetComCtlVersion
from the comctrls unit

as
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6478617
Alex is right. If you're importing SysUtils anyway (each project does by default), you should use this approach:

if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  ShowMessage('This system is win9x based.')
else if Win32Platform = VER_PLATFORM_WIN32_NT then
  ShowMessage('This system is winNT based.')
else
  ShowMessage('This system is not supported.');

You can also use this:

if GetVersion and $80000000 <> 0 then
  ShowMessage('This system is win9x based.')
else if Win32Platform = VER_PLATFORM_WIN32_NT then
  ShowMessage('This system is winNT based.');

If you need to have more power over the OS detection, you can have a look here:

http://help.madshi.net/Data/OSInfo.htm

Regards, Madshi.
0
 

Author Comment

by:tecmaster
ID: 6485384
The reason for the B is because you didn't fully answer the question.  mnasman provided the code which is what I specifically asked for.  Thank you for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multi-layered image in FireMonkey 9 93
Twebbrowser add css to the header 3 54
delphi popmenu non latine charcters 3 49
Problem working with dynamic array - help 2 48
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question