Solved

Getting the OS installed on the computer

Posted on 2003-11-25
14
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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