Solved

Getting the OS installed on the computer

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

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
Industry Leaders: 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 23

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 23

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 23

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 23

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 23

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

617 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