Solved

Getting the OS installed on the computer

Posted on 2003-11-25
14
321 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
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 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

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

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…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

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

21 Experts available now in Live!

Get 1:1 Help Now