Solved

Once again: detecting Windows operating system

Posted on 2001-07-03
18
197 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now