Solved

Getting the OS installed on the computer

Posted on 2003-11-25
14
318 Views
Last Modified: 2010-04-05
What I need is to make a a function that returns me what Operating system is installed on the comoputer. For example. Windows 2000 Server, Windows 2000 Professional, etc...
0
Comment
Question by:fabyola
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9820956
procedure TForm1.Button1Click(Sender: TObject);
Function GetVersionName:String;
var
      Key: HKEY;
      PT: array[0..80] of Char;
      BL: DWORD;
   AFOSVersionInfo: TOSVersionInfo;
begin
result := '';
AFOSVersionInfo.dwOSVersionInfoSize := SizeOf(AFOSVersionInfo);
If GetVersionEx(AFOSVersionInfo) then
begin
      case AFOSVersionInfo.dwPlatformId of
            VER_PLATFORM_WIN32s: result := 'Win32s';
            VER_PLATFORM_WIN32_WINDOWS:
            begin
                  case AFOSVersioninfo.dwMinorVersion of
                        0:    result := 'Windows 95';
                        10:   result := 'Windows 98';
                        90:   result := 'Windows ME'
                        else result := 'Unknown Win9x';
                  end;
            end;
            VER_PLATFORM_WIN32_NT:
            begin
            IF AFOSVersionInfo.dwMajorVersion <= 4 then
                     Result := 'Windows NT' else begin
                     case AFOSVersioninfo.dwMinorVersion of
                             0: result := 'Windows 2000';
                             1: result := 'Windows XP';
                          end;
            RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                              'SYSTEM\CurrentControlSet\Control\ProductOptions',
                              0, KEY_QUERY_VALUE, Key );
            RegQueryValueEx(Key, 'ProductType', nil, nil,@PT, @BL);
            RegCloseKey(Key);
            if AnsiCompareText('WINNT', PT) = 0 then
            Result := result + ' Professional';
            if AnsiCompareText('LANMANNT', PT) = 0 then
            Result := Result +' Server';
            if AnsiCompareText('SERVERNT', PT) = 0 then
            Result := Result+' Advanced Server';
            End;
      End;
      end;
end;
end;
begin
SHOWMESSAGE(GETVERSIONNAME);
end;

F68 ;-)
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 9822638
Try something like this:

var
// Global OS vars
VersionInfo: TOSVersionInfo;
Platform: string;
MajorVersion,MinorVersion,Build: DWORD;

procedure GetOSVersion;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
GetVersionEx(VersionInfo);

with VersionInfo do
begin
case dwPlatformId of
VER_PLATFORM_WIN32s: Platform := '3.1';
VER_PLATFORM_WIN32_WINDOWS : Platform := '98';
VER_PLATFORM_WIN32_NT:
begin
Case dwMajorVersion of
5 : Platform := '2000/NT';
else
Platform := 'NT';
end;
if dwBuildNumber > = 2500 then Platform := 'XP'
end;
end;

MajorVersion := dwMajorVersion;
MinorVersion := dwMinorVersion;
Build := dwBuildNumber;
end;
end;

Regards,

Hypoviax
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 9822646
Oh i forgot to say read from the platform variable to find the OS
0
 
LVL 10

Expert Comment

by:Jacco
ID: 9822940
In de jedi code library their is a very good function that knows all windows versions / service packs.

http://sourceforge.net/projects/jcl/

Regards Jacco
0
 

Author Comment

by:fabyola
ID: 9823658
Hypoviax, I can´t find it. What´s it´s name ??
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9823704
the way is that one posted by me...
Of course is also possible to get Service packs....tell me if you need it....
0
 

Author Comment

by:fabyola
ID: 9823733
Ferruccio68, Is there a way to get what service pack is installed too ??
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9823738
yes of course... wait a little....i'm implementing it...
0
 

Author Comment

by:fabyola
ID: 9823775
Yeah can you help me please ?
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 125 total points
ID: 9823829
well...here you are....this retrieve every OS version with SP value...

procedure TForm1.Button1Click(Sender: TObject);
Function GetVersionName:String;
var
     Key: HKEY;
     PT: array[0..80] of Char;
     BL: DWORD;
     AFOSVersionInfo: TOSVersionInfo;
     MaxVer, MinVer: Integer;
     CsdVersion: String;
begin
result := '';
AFOSVersionInfo.dwOSVersionInfoSize := SizeOf(AFOSVersionInfo);
If GetVersionEx(AFOSVersionInfo) then
begin
        MaxVer := AFOSVersionInfo.dwMajorVersion;
     MinVer := AFOSVersionInfo.dwMinorVersion;
     CSDVersion := AfOsVersionInfo.szCSDVersion;
     case AFOSVersionInfo.dwPlatformId of
          VER_PLATFORM_WIN32s: result := 'Win32s';
          VER_PLATFORM_WIN32_WINDOWS:
          begin
               case AFOSVersioninfo.dwMinorVersion of
                    0:    result := 'Windows 95';
                    10:   result := 'Windows 98';
                    90:   result := 'Windows ME'
                    else result := 'Unknown Win9x';
               end;
          if MaxVer = 4 then
             begin
               if (MinVer = 0)
                 and ((Trim(CSDVersion)[1] = 'C') or (Trim(CSDVersion)[1] = 'B')) then
                 Result := result + ' OSR2'
               else if (MinVer = 10) and (Trim(CSDVersion)[1] = 'A') then
                 Result := Result +' SE';
             end;
          end;
          VER_PLATFORM_WIN32_NT:
          begin
            IF AFOSVersionInfo.dwMajorVersion <= 4 then
                  Result := 'Windows NT' else begin
                  case AFOSVersioninfo.dwMinorVersion of
                         0: result := 'Windows 2000';
                         1: result := 'Windows XP';
                       end;
          RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                         'SYSTEM\CurrentControlSet\Control\ProductOptions',
                         0, KEY_QUERY_VALUE, Key );
          RegQueryValueEx(Key, 'ProductType', nil, nil,@PT, @BL);
          RegCloseKey(Key);
          if AnsiCompareText('WINNT', PT) = 0 then
          Result := result + ' Professional';
          if AnsiCompareText('LANMANNT', PT) = 0 then
          Result := Result +' Server';
          if AnsiCompareText('SERVERNT', PT) = 0 then
          Result := Result+' Advanced Server';
          result := result+' '+CSDVersion;
          End;
      End;
     end;
end;
end;
begin
SHOWMESSAGE(GETVERSIONNAME);
end;
0
 

Author Comment

by:fabyola
ID: 9823884
It worked like a charme. Thanx Alot. It will work on Windows 95 too ??? You showed me just what I needed.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9823914
yes of course...look this part:
[...]
case AFOSVersionInfo.dwPlatformId of
          VER_PLATFORM_WIN32s: result := 'Win32s'; //this means win 3.1
          VER_PLATFORM_WIN32_WINDOWS:
          begin
               case AFOSVersioninfo.dwMinorVersion of
                    0:    result := 'Windows 95';
                    10:   result := 'Windows 98';
                    90:   result := 'Windows ME'
                    else result := 'Unknown Win9x';
               end;
[...]
every Windows OS type is retrieved, so Win95 too...
0
 

Author Comment

by:fabyola
ID: 9823997
Thanx again Ferruccio68. When shows Advanced Server means that it´s a Windows NT Server ?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9824043
well this is what procuct type values mean:

WinNT = NT Workstation
ServerNT = NT Server
LanmanNT= NT Server (Enterprise Edition)
0

Featured Post

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).

Join & Write a Comment

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

9 Experts available now in Live!

Get 1:1 Help Now