Menu

[r202]: / branches / proxy-server / Src / USystemInfo.pas  Maximize  Restore  History

Download this file

234 lines (207 with data), 7.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{
* USystemInfo.pas
*
* Static class that provide information about the host system.
*
* Requires DelphiDabbler System information unit v3 or later.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is USystemInfo.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2006-2009 Peter
* Johnson. All Rights Reserved.
*
* Contributors:
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit USystemInfo;
interface
uses
// DelphiDabbler library
PJSysInfo;
type
{
TOSVer:
Record that records operation system major and minor version numbers.
}
TOSVer = packed record
VerHi: Word; // major OS version number
VerLo: Word; // minor OS version number
constructor Create(const AVerHi, AVerLo: Word);
{Record constructor. Sets initial field values.
@param AVerHi [in] Major version number.
@param AVerLo [in] Minor version number.
}
class operator GreaterThanOrEqual(const R1, R2: TOSVer): Boolean;
{Overload for >= operator on TOSVer.
@param R1 [in] First record to be checked.
@param R2 [in] Second record to be checked.
@return True in R1 >= R2, False otherwise.
}
end;
{
TOSInfo:
Exposes TPJOSInfo class to rest of program under a new name and extends to
add new methods.
}
TOSInfo = class(TPJOSInfo)
private
class function CheckForKernelFn(const FnName: string): Boolean;
{Checks if a specified function exists in OSs kernel.
@param FnName [in] Name of required function.
@return True if function is present in kernel, false if not.
}
public
const Win2K: TOSVer = (VerHi: 5; VerLo: 0);
{Identifies Windows 2K}
const WinXP: TOSVer = (VerHi: 5; VerLo: 1);
{Identifies Windows XP}
const WinVista: TOSVer = (VerHi: 6; VerLo: 0);
{Identifies Windows Vista}
class function IsVistaOrLater: Boolean;
{Checks if the underlying operating system is Windows Vista or later.
Ignores any OS emulation.
@return True if OS is Vista or later, False if not.
}
class function IsXPOrLater: Boolean;
{Checks if the underlying operating system is Windows XP or later. Ignores
any OS emulation.
@return True if OS is XP or later, False if not.
}
class function CheckReportedOS(const MinVer: TOSVer): Boolean;
{Checks if the OS reported by Windows is the same as or later than a
specified version number.
@param MinVer [in] Minimum OS version required.
@return True if OS reported by Windows is same as or later than MinVer.
}
class function BrowserVer: Word;
{Gets the major version number of the installed internet explorer browser.
Works for all version if IE from v4 onwards. See
http://support.microsoft.com/kb/969393/en-us.
@return Browser version >=4 or 0 if earlier browser or on error.
}
end;
implementation
uses
// Delphi
SysUtils, Registry, Windows,
// Project
UIStringList;
{ TOSInfo }
class function TOSInfo.BrowserVer: Word;
{Gets the major version number of the installed internet explorer browser.
Works for all version if IE from v4 onwards. See
http://support.microsoft.com/kb/969393/en-us.
@return Browser version >=4 or 0 if earlier browser or on error.
}
var
Reg: TRegistry; // registry access object
Vers: IStringList; // receives parts of version number string
const
cRegKey = 'Software\Microsoft\Internet Explorer'; // required registry key
cRegValue = 'Version'; // name of required registry value
begin
Result := 0;
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly(cRegKey) then
begin
if Reg.ValueExists(cRegValue) then
begin
Vers := TIStringList.Create(
Reg.ReadString(cRegValue), '.', False, True
);
// we want most significant version number
if (Vers.Count > 0) then
Result := StrToIntDef(Vers[0], 0);
end;
end;
finally
Reg.Free;
end;
end;
class function TOSInfo.CheckForKernelFn(const FnName: string): Boolean;
{Checks if a specified function exists in OSs kernel.
@param FnName [in] Name of required function.
@return True if function is present in kernel, false if not.
}
const
cKernelDLL = 'kernel32.dll'; // name of kernel DLL
var
PFunction: Pointer; // pointer to required function if exists
begin
// Try to load GetProductInfo func from Kernel32: present if Vista
PFunction := GetProcAddress(GetModuleHandle(cKernelDLL), PChar(FnName));
Result := Assigned(PFunction);
end;
class function TOSInfo.CheckReportedOS(const MinVer: TOSVer): Boolean;
{Checks if the OS reported by Windows is the same as or later than a specified
version number.
@param MinVer [in] Minimum OS version required.
@return True if OS reported by Windows is same as or later than MinVer.
}
begin
Result := TOSVer.Create(TOSInfo.MajorVersion, TOSInfo.MinorVersion)
>= MinVer;
end;
class function TOSInfo.IsVistaOrLater: Boolean;
{Checks if the underlying operating system is Windows Vista or later. Ignores
any OS emulation.
@return True if OS is Vista or later, False if not.
}
begin
// The "GetProductInfo" API function only exists in the kernel of Vista and
// Win 2008 server and later
Result := CheckForKernelFn('GetProductInfo');
end;
class function TOSInfo.IsXPOrLater: Boolean;
{Checks if the underlying operating system is Windows XP or later. Ignores
any OS emulation.
@return True if OS is XP or later, False if not.
}
begin
// The "ActivateActCtx" API function only exists in the kernel of XP and Win
// 2003 server and later
Result := CheckForKernelFn('ActivateActCtx');
end;
{ TOSVer }
constructor TOSVer.Create(const AVerHi, AVerLo: Word);
{Record constructor. Sets initial field values.
@param AVerHi [in] Major version number.
@param AVerLo [in] Minor version number.
}
begin
VerHi := AVerHi;
VerLo := AVerLo;
end;
class operator TOSVer.GreaterThanOrEqual(const R1, R2: TOSVer): Boolean;
{Overload for >= operator on TOSVer.
@param R1 [in] First record to be checked.
@param R2 [in] Second record to be checked.
@return True in R1 >= R2, False otherwise.
}
begin
Result := (R1.VerHi > R2.VerHi)
or ((R1.VerHi = R2.VerHi) and (R1.VerLo >= R2.VerLo));
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.