Solved

Code For Which OS In Use

Posted on 2001-09-12
9
191 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 207
Delphi: how to send PJL commands to printer 3 90
Delphi Mdi application Child forms get behind control 7 162
LAN or WAN ? 11 82
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

15 Experts available now in Live!

Get 1:1 Help Now