Solved

Code For Which OS In Use

Posted on 2001-09-12
9
190 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:mnasman
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

13 Experts available now in Live!

Get 1:1 Help Now