Solved

Code For Which OS In Use

Posted on 2001-09-12
9
192 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now