Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to detect the Windows OS version Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
10-Oct-02
Category
System
Language
Delphi 2.x
Views
118
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

How to detect the Windows OS version

Answer:

Solve 1:

1   uses
2     Windows;
3   
4   type
5     TWinVersion = (Win32, Win9x, WinNt, WinError);
6   
7   function fWinVersion: TWinVersion;
8   var
9     GV: TOSVersionInfo;
10  begin
11    GV.dwOSVersionInfoSize := Sizeof(GV);
12    if GetVersionEx(GV) then
13    begin
14      case GV.dwPlatformId of
15        VER_PLATFORM_WIN32s:
16          Result := Win32;
17        VER_PLATFORM_WIN32_WINDOWS:
18          Result := Win9x;
19        VER_PLATFORM_WIN32_NT:
20          Result := WinNT;
21      else
22        Result := WinError;
23      end;
24    end
25    else
26      Result := WinError;
27  end;



Solve 2:

28  type
29    PTransBuffer = ^TTransBuffer;
30    TTransBuffer = array[1..4] of smallint;
31  
32  const
33    CInfoStr: array[1..4] of string = ('FileVersion', 'LegalCopyright', 'ProductName',
34      'ProductVersion');
35  
36  procedure TFrmAbout.GetVersionInfo(AVersionList: TStrings);
37  var
38    filename: string;
39    i: integer;
40    infoSize: DWORD;
41    ptrans: PTransBuffer;
42    transStr: string;
43    typeStr: string;
44    value: PChar;
45    verBuf: pointer;
46    verSize: DWORD;
47    wnd: DWORD;
48  begin
49    AVersionList.Clear;
50    filename := Application.ExeName;
51    infoSize := GetFileVersioninfoSize(PChar(filename), wnd);
52    if infoSize <> 0 then
53    begin
54      GetMem(verBuf, infoSize);
55      try
56        if GetFileVersionInfo(PChar(filename), wnd, infoSize, verBuf) then
57        begin
58          VerQueryvalue(verBuf, PChar('\VarFileInfo\Translation'), Pointer(ptrans),
59            verSize);
60          transStr := IntToHex(ptrans^[1], 4) + IntToHex(ptrans^[2], 4);
61          for i := Low(CInfoStr) to High(CInfoStr) do
62          begin
63            typeStr := 'StringFileInfo\' + transStr + '\' + CInfoStr[i];
64            if VerQueryvalue(verBuf, PChar(typeStr), Pointer(value), verSize) then
65              {AVersionList.Add(CInfoStr[i] + ': ' + value);}
66              AVersionList.Add(value);
67          end
68        end;
69      finally
70        FreeMem(verBuf);
71      end;
72    end;
73  end;



Solve 3:

Delphi 5 has a variable Win32Platform in SysUtils

74  var
75    Win32Platform: Integer = 0;


It will have 3 values

VER_PLATFORM_32s
VER_PLATFORM_WIN32_WINDOWS
VER_PLATFORM_WIN32_WIN_NT


Solve 4:

76  { ... }
77  case Win32MajorVersion of
78    3: {NT 3.51}
79      OSLabel.Caption := 'Windows NT 3.51';
80    4: {WIn9x/ME, NT 4}
81      case Win32MinorVersion of
82        0:
83          OSLabel.Caption := 'Windows 95';
84        10:
85          OSLabel.Caption := 'Windows 98';
86        90:
87          OSLabel.Caption := 'Windows ME';
88      else
89        if (Win32Platform and VER_PLATFORM_WIN32_NT) <> 0 then
90          OSLabel.Caption := 'Windows NT 4.0'
91        else
92          OSLabel.Caption := 'unknown';
93      end;
94    5: {Win2K, XP}
95      case Win32MinorVersion of
96        0:
97          OSLabel.Caption := 'Windows 2000';
98        1:
99          OSLabel.Caption := 'Windows XP or .NET server';
100     else
101       OSLabel.Caption := 'unknown';
102     end;
103 else
104   OSLabel.Caption := 'unknown';
105 end;



Solve 5:
106 
107 function GetOSInfo: string;
108 var
109   Platform: string;
110   BuildNumber: integer;
111 begin
112   case Win32MajorVersion of
113     3: {NT 3.51}
114       Platform := 'Windows NT 3.51';
115     4: {Win9x/ ME/ NT 4}
116       case Win32MinorVersion of
117         0:
118           Platform := 'Windows 95';
119         10:
120           Platform := 'Windows 98';
121         90:
122           Platform := 'Windows ME';
123       else
124         if (Win32Platform and VER_PLATFORM_WIN32_NT) <> 0 then
125           Platform := 'Windows NT 4.0'
126         else
127           Platform := SUnknown;
128       end;
129     5: {Win2000/ XP}
130       case Win32MinorVersion of
131         0:
132           Platform := 'Windows 2000';
133         1:
134           Platform := 'Windows XP or .NET server';
135       else
136         Platform := SUnknown;
137       end;
138   else
139     Platform := SUnknown;
140   end;
141   case Win32Platform of
142     VER_PLATFORM_WIN32_WINDOWS:
143       BuildNumber := Win32BuildNumber and $0000FFFF;
144     VER_PLATFORM_WIN32_NT:
145       BuildNumber := Win32BuildNumber;
146   else
147     BuildNumber := 0;
148   end;
149   if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) or
150     (Win32Platform = VER_PLATFORM_WIN32_NT) then
151   begin
152     if Win32CSDVersion = '' then
153       Result := Format('%s (Build %d)', [Platform, BuildNumber])
154     else
155       Result := Format('%s (Build %d: %s)', [Platform, BuildNumber, 
156 Win32CSDVersion]);
157   end
158   else
159     Result := Platform;
160 end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC