Solved

Once again: detecting Windows operating system

Posted on 2001-07-03
18
205 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
proper way to parse text with delphi 7 121
How to debug For loops? 3 49
DBCtrlGrid, Delphi, Scroll 8 14
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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