Solved

Code For Which OS In Use

Posted on 2001-09-12
9
197 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

623 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