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
Solved

Once again: detecting Windows operating system

Posted on 2001-07-03
18
209 Views
Last Modified: 2010-04-06
Hi experts,

I still have problems to detect the operationg system.
I already asked this question when I was still using Windows 98.
Now as I migrated to Windows 2000 I fozund out that zje OS on my maschine is not
detected correctly.

On my PC I get the message

"Unknown OS 5.0"

Actually I'd like to see

"Windows 2000"


Can you please tell me, what I am doing wrong here?


....
os.dwOSVersionInfoSize := sizeof(os);
    if GetVersionEx(os) then
    begin
      majorVer := osVerInfo.dwMajorVersion;
      minorVer := osVerInfo.dwMinorVersion;
      case os.dwPlatformId of
        VER_PLATFORM_WIN32s: zw := 'Win32s under Windows 3.x';
        VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME }
          begin
            if (majorVer = 4) and (minorVer = 0) then
              zw := 'Windows 95'
            else if (majorVer = 4) and (minorVer = 10) then
            begin
              if osVerInfo.szCSDVersion[1] = 'A' then
                zw := 'Windows 98 SE'
              else
                zw := 'Windows 98';
            end
            else if (majorVer = 4) and (minorVer = 90) then
              zw := 'Windows ME'
            else
              zw := 'Unknown OS ';
          end;
        VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
          begin
            if majorVer <= 4 then
              zw := 'Windows NT'
            else if (majorVer = 5) and (minorVer = 0) then
              zw := 'Windows 2000'
            else if (majorVer = 5) and (minorVer = 1) then
              zw := 'Windows Whistler'
            else
              zw := 'Unknown OS';
          end;
      end;
.....    
0
Comment
Question by:mathes
  • 5
  • 5
  • 4
  • +2
18 Comments
 
LVL 3

Expert Comment

by:VSF
ID: 6250450
Try this and see if it helps!

VSF
www.victory.hpg.com.br
www.enge.cjb.net
UIN:14016999

unit AboutSO;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,Buttons, ExtCtrls;

type
  TfrmAboutSO = class(TForm)
    btnOK: TButton;
    ProductName: TLabel;
    Version: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Copyright: TLabel;
    Panel1: TPanel;
    Image2: TImage;
    GroupBox1: TGroupBox;
    Bevel1: TBevel;
    stOSVersao: TStaticText;
    stOSBuilder: TStaticText;
    stOS: TStaticText;
    stOSService: TStaticText;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmAboutSO: TfrmAboutSO;

implementation

{$R *.DFM}

procedure TfrmAboutSO.FormCreate(Sender: TObject);
var
  verInfo : TOsVersionInfo;
  str     : String;
  I       : Word;
begin
  verInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  if GetVersionEx(verInfo) then begin
    stOSVersao.Caption := 'Version : '+ IntToStr(verInfo.dwMajorVersion) +
                                 IntToStr(verInfo.dwMinorVersion);
    stOSBuilder.Caption := 'Compilation : '+IntToStr(verInfo.dwBuildNumber);
    str := 'S.O. : ';
    case verInfo.dwPlatformId of
      VER_PLATFORM_WIN32s         : stOS.Caption := str +'Windows 95';
      VER_PLATFORM_WIN32_WINDOWS  : stOS.Caption := str +'Windows 95 Osr2 / 98';
      VER_PLATFORM_WIN32_NT       : stOS.Caption := str +'Windows NT';
    end;

    str := '';

    for I := 0 to 127 do
      str := str + verInfo.szCSDVersion[I];

    stOSService.Caption := 'Aditional Info : '+ str;
  end
end;
end.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6250452
What values do dwMajorVersion, dwMajorVersion and dwPlatformId have right after the call to GetVersionEx?
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6250453
That is almost exactly the same code I have here (only difference really is variable names and the order I did things).  If you do a ShowMessage(IntToStr(MajorVer) + '.' + IntToStr(MinorVer)); what does it say?
0
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.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6250454
Maybe you should avoid using dwPlatformId and only use dwMajorVersion and dwMajorVersion...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6250462
ehhh.. dwMinorVersion and dwMajorVersion  :o)
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6250467
One thing I just noticed after looking again is this:

if GetVersionEx(os) then
   begin
     majorVer := osVerInfo.dwMajorVersion;
     minorVer := osVerInfo.dwMinorVersion;

You retrieve the info into the variable "os" but assign values to "majorVer" and "minorVer" using the "osVerInfo" variable.  Unless there is more code above these lines that you didnt paste into your message, I would bet this is where the problem is.
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6250473
One thing I just noticed after looking again is this:

if GetVersionEx(os) then
   begin
     majorVer := osVerInfo.dwMajorVersion;
     minorVer := osVerInfo.dwMinorVersion;

You retrieve the info into the variable "os" but assign values to "majorVer" and "minorVer" using the "osVerInfo" variable.  Unless there is more code above these lines that you didnt paste into your message, I would bet this is where the problem is.
0
 
LVL 3

Expert Comment

by:VSF
ID: 6250480
My Code should do it. Have u tested?!
0
 
LVL 3

Expert Comment

by:VSF
ID: 6250512
My Code should do it. Have u tested?!
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6251423
listening :-)
0
 

Author Comment

by:mathes
ID: 6251755
VSF: Do you think hat your code will recognize Windows 3.1 ?
0
 

Author Comment

by:mathes
ID: 6251756
Hi experts,

today I post the complete source code of the procedure.
Now you can more easilsy find out, if some important things are missing:


procedure TfrmSystemInfo.FormActivate(Sender: TObject);
var
  p: PChar;
  zw: string;
  dc: hdc;
  memory: TMEMORYSTATUS;
  systeminfo: TSystemInfo;
  dw: dword;
  os: TOSVERSIONINFO;
  majorVer, minorVer: Integer;
  osVerInfo: TOSVersionInfo;
begin

  with stringgrid1 do begin
    colwidths[0] := clientwidth div 2;
    colwidths[1] := clientwidth div 2;
    memory.dwLength := sizeof(memory);
    GlobalMemoryStatus(memory);
    cells[0, 0] := 'phys. Speicher'; cells[1, 0] := inttostr(memory.dwTotalPhys) + ' Bytes';
    cells[0, 1] := 'phys. Speicher frei'; cells[1, 1] := inttostr(memory.dwAvailPhys) + ' Bytes';
    cells[0, 2] := 'Auslagerungsspeicher'; cells[1, 2] := inttostr(memory.dwTotalPageFile) + ' Bytes';
    cells[0, 3] := 'Auslagerungsspeicher frei'; cells[1, 3] := inttostr(memory.dwAvailPageFile) + ' Bytes';
    P := StrAlloc(MAX_PATH + 1);
    GetWindowsDirectory(P, MAX_PATH + 1);
    cells[0, 4] := 'Windowsverzeichnis'; cells[1, 4] := p;
    StrDispose(P);
    P := StrAlloc(MAX_PATH + 1);
    GetSystemDirectory(P, MAX_PATH + 1);
    cells[0, 5] := 'Systemverzeichnis'; cells[1, 5] := p;
    StrDispose(P);
    GetSystemInfo(systeminfo);
    cells[0, 6] := 'Prozessor(en)'; cells[1, 6] := inttostr(systeminfo.dwNumberOfProcessors);
    case systeminfo.dwProcessorType of
      386: zw := 'Intel 386';
      486: zw := 'Intel 486';
      586: zw := 'Intel Pentium';
      860: zw := 'Intel 860';
      2000: zw := 'MIPS R2000';
      3000: zw := 'MIPS R3000';
      4000: zw := 'MIPS R4000';
      21064: zw := 'ALPHA 21064';
      601: zw := 'PPC 601';
      603: zw := 'PPC 603';
      604: zw := 'PPC 604';
      620: zw := 'PPC 620';
    end;
    cells[0, 7] := 'Prozessor'; cells[1, 7] := zw;
    cells[0, 8] := 'Zeit'; cells[1, 8] := timetostr(time);
    cells[0, 9] := 'Zeit seit Systemstart'; cells[1, 9] := timetostr(getcurrenttime / 60000000);
    cells[0, 10] := 'Datum'; cells[1, 10] := datetostr(date);
    cells[0, 11] := 'Grafikaufl?sung'; cells[1, 11] := inttostr(screen.width) + 'x' + inttostr(screen.height);
    dc := GetDC(0);
    cells[0, 12] := 'Farben';
    cells[1, 12] := inttostr(1 shl GetDeviceCaps(dc, BITSPIXEL));
    ReleaseDC(0, dc);
    dw := 255;
    P := StrAlloc(256);
    GetUserName(p, dw);
    cells[0, 13] := 'Username'; cells[1, 13] := p;
    StrDispose(P);
    P := StrAlloc(256);
    GetComputerName(p, dw);
    cells[0, 14] := 'Computername'; cells[1, 14] := p;
    StrDispose(P);
    os.dwOSVersionInfoSize := sizeof(os);
    if GetVersionEx(os) then
    begin
      majorVer := osVerInfo.dwMajorVersion;
      minorVer := osVerInfo.dwMinorVersion;
      case os.dwPlatformId of
        VER_PLATFORM_WIN32s: zw := 'Win32s unter Windows 3.x';
        VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME }
          begin
            if (majorVer = 4) and (minorVer = 0) then
              zw := 'Windows 95'
            else if (majorVer = 4) and (minorVer = 10) then
            begin
              if osVerInfo.szCSDVersion[1] = 'A' then
                zw := 'Windows 98 SE'
              else
                zw := 'Windows 98';
            end
            else if (majorVer = 4) and (minorVer = 90) then
              zw := 'Windows ME'
            else
              zw := 'Unbekanntes Betriebssystem';
          end;
        VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
          begin
            if majorVer <= 4 then
              zw := 'Windows NT'
            else if (majorVer = 5) and (minorVer = 0) then
              zw := 'Windows 2000'
            else if (majorVer = 5) and (minorVer = 1) then
              zw := 'Windows Whistler'
            else
              zw := 'Unbekanntes Betriebssystem';
          end;
      end;
      cells[0, 15] := 'Betriebssystem'; cells[1, 15] := zw + ' ' + inttostr(os.dwMajorVersion) + '.' + inttostr(os.dwMinorVersion);
    end;
  end;
end;
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 6251913
Mathes, you should read the comment better:

change

     majorVer := osVerInfo.dwMajorVersion;
     minorVer := osVerInfo.dwMinorVersion;

to

     majorVer := os.dwMajorVersion;
     minorVer := os.dwMinorVersion;
0
 

Author Comment

by:mathes
ID: 6251946
Thank you for your help. It works perfectly now.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6251975
Well, thank you, but I think Mannsoft should have had the points...
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6252118
It's ok, I dont need the points anyway.  As long as it's working now it's all good.
0
 

Author Comment

by:mathes
ID: 6252132
Hi experts,

well, I recieve so many good relies from you experts. Often it is very difficult to reward the right person with points. I know I am not always fair with my judgements. But the huge number of useful things which you can learn here speaks for the high quality of this web forum.
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 6253839
I think Epsylon meant I should have gotten the points because I pointed out the problem almost right away.  But apparently you didnt understand what I was saying so he repeated it as an explicit instruction.  I should have just been more clear I guess.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 238
creating threads in delphi 1 132
Delphi...Split view - idea? 1 89
DBCtrlGrid, Delphi, Scroll 7 26
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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