Solved

Getting the OS installed on the computer

Posted on 2003-11-25
14
322 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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