18. august 2003 - 14:11
#3
prøv den her :
unit OS;
interface
uses
SysUtils, Windows, Classes;
type
TTimeZone = class(TPersistent)
private
FStdBias: integer;
FDayBias: integer;
FBias: integer;
FDisp: string;
FStd: string;
FDayStart: TDatetime;
FStdStart: TDatetime;
FDay: string;
FMap: string;
public
procedure GetInfo;
procedure Report(var sl: TStringList);
property MapID: string read FMap;
published
property DisplayName: string read FDisp write FDisp stored False;
property StandardName: string read FStd write FStd stored False;
property DaylightName: string read FDay write FDay stored False;
property DaylightStart: TDatetime read FDayStart write FDayStart stored False;
property StandardStart: TDatetime read FStdStart write FStdStart stored False;
property Bias: integer read FBias write FBias stored False;
property DaylightBias: integer read FDayBias write FDayBias stored False;
property StandardBias: integer read FStdBias write FStdBias stored False;
end;
const
VER_NT_WORKSTATION = $0000001;
VER_NT_DOMAIN_CONTROLLER = $0000002;
VER_NT_SERVER = $0000003;
type
POSVersionInfoEx = ^TOSVersionInfoEx;
TOSVersionInfoEx = record
dwOSVersionInfoSize: DWORD;
dwMajorVersion: DWORD;
dwMinorVersion: DWORD;
dwBuildNumber: DWORD;
dwPlatformId: DWORD;
szCSDVersion: array[0..127] of Char;
wServicePackMajor: Word;
wServicePackMinor: Word;
wSuiteMask: Word;
wProductType: Byte;
wReserved: Byte;
end;
TNtProductType = (ptUnknown, ptWorkStation, ptServer, ptAdvancedServer);
TOperatingSystem = class(TPersistent)
private
FBuildNumber: integer;
FMajorVersion: integer;
FMinorVersion: integer;
FPlatform: string;
FCSD: string;
FVersion: string;
FRegUser: string;
FSerialNumber: string;
FRegOrg: string;
FEnv: TStrings;
FDirs: TStrings;
FTZ: TTimeZone;
FNTPT: TNTProductType;
procedure GetEnvironment;
protected
public
constructor Create;
destructor Destroy; override;
procedure GetInfo;
procedure Report(var sl: TStringList);
published
property MajorVersion: integer read FMajorVersion write FMajorVersion stored false;
property MinorVersion: integer read FMinorVersion write FMinorVersion stored false;
property BuildNumber: integer read FBuildNumber write FBuildNumber stored false;
property Platform: string read FPlatform write FPlatform stored false;
property Version: string read FVersion write FVersion stored false;
property CSD: string read FCSD write FCSD stored false;
property SerialNumber: string read FSerialNumber write FSerialNumber stored false;
property RegisteredUser: string read FRegUser write FRegUser stored false;
property RegisteredOrg: string read FRegOrg write FRegOrg stored false;
property TimeZone: TTimeZone read FTZ write FTZ stored false;
property Environment: TStrings read FEnv write FEnv stored false;
property Folders: TStrings read FDirs write FDirs stored False;
property NTProductType: TNTProductType read FNTPT write FNTPT stored False;
end;
function GetVersionEx(lpVersionInformation: POSVersionInfoEx): BOOL; stdcall;
implementation
uses
ShlObj, Registry, Routines;
function GetVersionEx; external kernel32 name 'GetVersionExA';
const
CSIDL_COMMON_ALTSTARTUP = $001E;
CSIDL_COMMON_FAVORITES = $001F;
CSIDL_INTERNET_CACHE = $0020;
CSIDL_COOKIES = $0021;
CSIDL_HISTORY = $0022;
CSIDL_INTERNET = $0001;
{ TTimeZone }
type
TRegTimeZoneInfo = packed record
Bias: Longint;
StandardBias: Longint;
DaylightBias: Longint;
StandardDate: TSystemTime;
DaylightDate: TSystemTime;
end;
function IsLeapYear(Year: Word): Boolean;
begin
Result := ((Year and 3) = 0) and ((Year mod 100 > 0) or (Year mod 400 = 0));
end;
function DaysInMonth(const DT: TDateTime): Byte;
var
y, m, d: Word;
begin
DecodeDate(DT, y, m, d);
case m of
2: if IsLeapYear(y) then
Result := 29
else
Result := 28;
4, 6, 9, 11: Result := 30;
else
Result := 31;
end;
end;
function DayOfMonth2Date(year, month, weekInMonth, dayInWeek: word): TDateTime;
var
days: integer;
day: integer;
begin
if (weekInMonth >= 1) and (weekInMonth <= 4) then
begin
day := DayOfWeek(EncodeDate(year, month, 1));
day := 1 + dayInWeek - day;
if day <= 0 then
Inc(day, 7);
day := day + 7 * (weekInMonth - 1);
Result := EncodeDate(year, month, day);
end
else if weekInMonth = 5 then
begin
days := DaysInMonth(EncodeDate(year, month, 1));
day := DayOfWeek(EncodeDate(year, month, days));
day := days + (dayInWeek - day);
if day > days then
Dec(day, 7);
Result := EncodeDate(year, month, day);
end
else
Result := 0;
end;
function DSTDate2Date(dstDate: TSystemTime; year: word): TDateTime;
begin
if dstDate.wMonth = 0 then
Result := 0
else if dstDate.wYear = 0 then
Result := DayOfMonth2Date(year, dstDate.wMonth, dstDate.wDay, dstDate.wDayOfWeek + 1) +
EncodeTime(dstDate.wHour, dstDate.wMinute, dstDate.wSecond, dstDate.wMilliseconds)
else
Result := SystemTimeToDateTime(dstDate);
end;
function GetTZDaylightSavingInfoForYear(
TZ: TTimeZoneInformation; year: word;
var DaylightDate, StandardDate: TDateTime;
var DaylightBias, StandardBias: longint): boolean;
begin
Result := false;
try
if (TZ.DaylightDate.wMonth <> 0) and
(TZ.StandardDate.wMonth <> 0) then
begin
DaylightDate := DSTDate2Date(TZ.DaylightDate, year);
StandardDate := DSTDate2Date(TZ.StandardDate, year);
DaylightBias := TZ.Bias + TZ.DaylightBias;
StandardBias := TZ.Bias + TZ.StandardBias;
Result := true;
end;
except
end;
end;
function CompareSysTime(st1, st2: TSystemTime): integer;
begin
if st1.wYear < st2.wYear then
Result := -1
else if st1.wYear > st2.wYear then
Result := 1
else if st1.wMonth < st2.wMonth then
Result := -1
else if st1.wMonth > st2.wMonth then
Result := 1
else if st1.wDayOfWeek < st2.wDayOfWeek then
Result := -1
else if st1.wDayOfWeek > st2.wDayOfWeek then
Result := 1
else if st1.wDay < st2.wDay then
Result := -1
else if st1.wDay > st2.wDay then
Result := 1
else if st1.wHour < st2.wHour then
Result := -1
else if st1.wHour > st2.wHour then
Result := 1
else if st1.wMinute < st2.wMinute then
Result := -1
else if st1.wMinute > st2.wMinute then
Result := 1
else if st1.wSecond < st2.wSecond then
Result := -1
else if st1.wSecond > st2.wSecond then
Result := 1
else if st1.wMilliseconds < st2.wMilliseconds then
Result := -1
else if st1.wMilliseconds > st2.wMilliseconds then
Result := 1
else
Result := 0;
end;
function IsEqualTZ(tz1, tz2: TTimeZoneInformation): boolean;
begin
Result := (tz1.Bias = tz2.Bias) and
(tz1.StandardBias = tz2.StandardBias) and
(tz1.DaylightBias = tz2.DaylightBias) and
(CompareSysTime(tz1.StandardDate, tz2.StandardDate) = 0) and
(CompareSysTime(tz1.DaylightDate, tz2.DaylightDate) = 0) and
(WideCharToString(tz1.StandardName) = WideCharToString(tz2.StandardName)) and
(WideCharToString(tz1.DaylightName) = WideCharToString(tz2.DaylightName));
end;
procedure TTimeZone.GetInfo;
var
TZKey: string;
RTZ: TRegTimeZoneInfo;
HomeTZ, RegTZ: TTimeZoneInformation;
y, m, d, i: Word;
sl: TStringList;
const
rkNTTimeZones = {HKEY_LOCAL_MACHINE\} 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones';
rk9xTimeZones = {HKEY_LOCAL_MACHINE\} 'SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones';
rkTimeZone = {HKEY_LOCAL_MACHINE\} 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation';
rvTimeZone = 'StandardName';
begin
GetTimeZoneInformation(HomeTZ);
sl := TStringList.Create;
with TRegistry.create do
begin
rootkey := HKEY_LOCAL_MACHINE;
if IsNT then
TZKey := rkNTTimeZones
else
TZKey := rk9xTimeZones;
if OpenKey(TZKey, False) then
begin
GetKeyNames(sl);
CloseKey;
for i := 0 to sl.Count - 1 do
if OpenKey(TZKey + '\' + sl[i], False) then
begin
if GetDataSize('TZI') = SizeOf(RTZ) then
begin
ReadBinaryData('TZI', RTZ, SizeOf(RTZ));
StringToWideChar(ReadString('Std'), @RegTZ.StandardName, SizeOf(RegTZ.StandardName) div SizeOf(WideChar));
StringToWideChar(ReadString('Dlt'), @RegTZ.DaylightName, SizeOf(RegTZ.DaylightName) div SizeOf(WideChar));
RegTZ.Bias := RTZ.Bias;
RegTZ.StandardBias := RTZ.StandardBias;
RegTZ.DaylightBias := RTZ.DaylightBias;
RegTZ.StandardDate := RTZ.StandardDate;
RegTZ.DaylightDate := RTZ.DaylightDate;
if IsEqualTZ(HomeTZ, RegTZ) then
begin
FDisp := ReadString('Display');
try
FMap := ReadString('MapID');
except
FMap := '';
end;
Break;
end;
end;
CloseKey;
end;
end;
Free;
end;
FBias := HomeTZ.Bias;
FStd := HomeTZ.StandardName;
FDay := HomeTZ.DaylightName;
DecodeDate(Date, y, m, d);
GetTZDaylightSavingInfoForYear(HomeTZ, y, FDayStart, FStdStart, FDayBias, FStdBias);
sl.Free;
end;
procedure TTimeZone.Report(var sl: TStringList);
begin
with sl do
begin
Add('[Time Zone]');
Add(Format('TimeZone=%s', [DisplayName]));
Add(Format('StdName=%s', [DateTimeToStr(StandardStart)]));
Add(Format('StdBias=%d', [StandardBias]));
Add(Format('DlghtName=%s', [DateTimeToStr(DaylightStart)]));
Add(Format('DlghtBias=%d', [DaylightBias]));
end;
end;
{ TOperatingSystem }
constructor TOperatingSystem.Create;
begin
inherited;
FEnv := TStringList.Create;
FDirs := TStringList.Create;
FTZ := TTimeZone.Create;
end;
destructor TOperatingSystem.Destroy;
begin
FEnv.Free;
FDirs.Free;
FTZ.Free;
inherited;
end;
procedure TOperatingSystem.GetEnvironment;
var
c, i: dword;
b: pchar;
s: string;
begin
FEnv.Clear;
c := 1024;
b := GetEnvironmentStrings;
i := 0;
s := '';
while i < c do
begin
if b[i] <> #0 then
s := s + b[i]
else
begin
if s = '' then
break;
FEnv.Add(s);
s := '';
end;
inc(i);
end;
FreeEnvironmentStrings(b);
end;
function GetSpecialFolder(Handle: Hwnd; nFolder: Integer): string;
var
PIDL: PItemIDList;
Path: LPSTR;
begin
Result := '';
Path := StrAlloc(MAX_PATH);
SHGetSpecialFolderLocation(Handle, nFolder, PIDL);
if SHGetPathFromIDList(PIDL, Path) then
Result := StrPas(Path);
StrDispose(Path);
end;
function ReverseStr(S: string): string;
var
l, i: integer;
begin
l := Length(s);
Result := '';
for i := 0 to l - 1 do
Result := Result + s[l - i];
end;
procedure TOperatingSystem.GetInfo;
var
OS: TOSVersionInfo;
OK: Boolean;
p: pchar;
n: DWORD;
WinH: HWND;
s: string;
VersionInfo: TOSVersionInfoEx;
const
rkOSInfo95 = {HKEY_LOCAL_MACHINE\} 'SOFTWARE\Microsoft\Windows\CurrentVersion';
rkOSInfoNT = {HKEY_LOCAL_MACHINE\} 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
rvVersionName95 = 'Version';
rvVersionNameNT = 'CurrentType';
rvRegOrg = 'RegisteredOrganization';
rvRegOwn = 'RegisteredOwner';
rvProductID = 'ProductID';
rkProductTypeNT = {HKEY_LOCAL_MACHINE\} 'System\CurrentControlSet\Control\ProductOptions';
rvProductType = 'ProductType';
cUserProfile = 'USERPROFILE';
cUserProfileReg = {HKEY_CURRENT_USER\} 'Software\Microsoft\Windows\CurrentVersion\ProfileList';
cUserProfileRec = {HKEY_CURRENT_USER\} 'SOFTWARE\Microsoft\Windows\CurrentVersion\ProfileReconciliation';
cProfileDir = 'ProfileDirectory';
begin
FDirs.Clear;
TimeZone.GetInfo;
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
Windows.GetVersionEx(OS);
MajorVersion := OS.dwMajorVersion;
MinorVersion := OS.dwMinorVersion;
BuildNumber := word(OS.dwBuildNumber);
case OS.dwPlatformId of
VER_PLATFORM_WIN32s: Platform := 'Windows 3.1x';
VER_PLATFORM_WIN32_WINDOWS: Platform := 'Windows 95';
VER_PLATFORM_WIN32_NT: Platform := 'Windows NT';
end;
if MajorVersion = 5 then
Platform := 'Windows 2000';
CSD := strpas(OS.szCSDVersion);
FNTPT := ptUnknown;
if (OS.dwPlatformId = VER_PLATFORM_WIN32_NT) and (MajorVersion = 5) then
begin
FillChar(VersionInfo, SizeOf(VersionInfo), 0);
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
if GetVersionEx(@VersionInfo) then
case VersionInfo.wProductType of
VER_NT_WORKSTATION: FNTPT := ptWorkStation;
VER_NT_DOMAIN_CONTROLLER: FNTPT := ptAdvancedServer;
VER_NT_SERVER: FNTPT := ptServer;
end;
end;
Version := '';
RegisteredUser := '';
RegisteredOrg := '';
SerialNumber := '';
with TRegistry.create do
begin
rootkey := HKEY_LOCAL_MACHINE;
if isnt then
begin
if OpenKey(rkOSInfoNT, false) then
begin
if ValueExists(rvVersionNameNT) then
Version := ReadString(rvVersionNameNT);
if ValueExists(rvRegOrg) then
RegisteredOrg := ReadString(rvRegOrg);
if ValueExists(rvRegOwn) then
RegisteredUser := ReadString(rvRegOwn);
if ValueExists(rvProductID) then
SerialNumber := ReadString(rvProductID);
closekey;
end;
if FNTPT = ptUnknown then
begin
if OpenKey(rkProductTypeNT, False) then
begin
s := ReadString(rvProductType);
if s = 'WinNT' then
FNTPT := ptWorkStation
else if s = 'ServerNT' then
FNTPT := ptServer
else if s = 'LanmanNT' then
FNTPT := ptAdvancedServer;
CloseKey;
end;
end;
end
else
begin
if OpenKey(rkOSInfo95, false) then
begin
if ValueExists(rvVersionName95) then
Version := ReadString(rvVersionName95);
if ValueExists(rvRegOrg) then
RegisteredOrg := ReadString(rvRegOrg);
if ValueExists(rvRegOwn) then
RegisteredUser := ReadString(rvRegOwn);
if ValueExists(rvProductID) then
SerialNumber := ReadString(rvProductID);
closekey;
end;
end;
rootkey := HKEY_LOCAL_MACHINE;
if IsNT then
OK := OpenKey(rkOSInfoNT, False)
else
OK := OpenKey(rkOSInfo95, False);
if OK then
begin
FDirs.Add('CommonFiles=' + ReadString('CommonFilesDir'));
FDirs.Add('ProgramFiles=' + ReadString('ProgramFilesDir'));
FDirs.Add('Device=' + ReadString('DevicePath'));
FDirs.Add('OtherDevice=' + ReadString('OtherDevicePath'));
FDirs.Add('Media=' + ReadString('MediaPath'));
FDirs.Add('Config=' + ReadString('ConfigPath'));
FDirs.Add('Wallpaper=' + ReadString('WallPaperDir'));
CloseKey;
end;
Free;
end;
n := MAX_PATH;
p := StrAlloc(n);
GetWindowsDirectory(p, n);
FDirs.Add('Windows=' + StrPas(p));
GetSystemDirectory(p, n);
FDirs.Add('System=' + StrPas(p));
GetTempPath(n, p);
FDirs.Add('Temp=' + StrPas(p));
StrDispose(p);
WinH := GetDesktopWindow;
FDirs.Add('AppData=' + GetSpecialFolder(WinH, CSIDL_APPDATA));
FDirs.Add('CommonDesktopDir=' + GetSpecialFolder(WinH, CSIDL_COMMON_DESKTOPDIRECTORY));
FDirs.Add('CommonAltStartUp=' + GetSpecialFolder(WinH, CSIDL_COMMON_ALTSTARTUP));
FDirs.Add('RecycleBin=' + GetSpecialFolder(WinH, CSIDL_BITBUCKET));
FDirs.Add('CommonPrograms=' + GetSpecialFolder(WinH, CSIDL_COMMON_PROGRAMS));
FDirs.Add('CommonStartMenu=' + GetSpecialFolder(WinH, CSIDL_COMMON_STARTMENU));
FDirs.Add('CommonStartup=' + GetSpecialFolder(WinH, CSIDL_COMMON_STARTUP));
FDirs.Add('CommonFavorites=' + GetSpecialFolder(WinH, CSIDL_COMMON_FAVORITES));
FDirs.Add('Cookies=' + GetSpecialFolder(WinH, CSIDL_COOKIES));
FDirs.Add('Controls=' + GetSpecialFolder(WinH, CSIDL_CONTROLS));
FDirs.Add('Desktop=' + GetSpecialFolder(WinH, CSIDL_DESKTOP));
FDirs.Add('DesktopDir=' + GetSpecialFolder(WinH, CSIDL_DESKTOPDIRECTORY));
FDirs.Add('Favorites=' + GetSpecialFolder(WinH, CSIDL_FAVORITES));
FDirs.Add('Drives=' + GetSpecialFolder(WinH, CSIDL_DRIVES));
FDirs.Add('Fonts=' + GetSpecialFolder(WinH, CSIDL_FONTS));
FDirs.Add('History=' + GetSpecialFolder(WinH, CSIDL_HISTORY));
FDirs.Add('Internet=' + GetSpecialFolder(WinH, CSIDL_INTERNET));
FDirs.Add('InternetCache=' + GetSpecialFolder(WinH, CSIDL_INTERNET_CACHE));
FDirs.Add('NetWork=' + GetSpecialFolder(WinH, CSIDL_NETWORK));
FDirs.Add('NetHood=' + GetSpecialFolder(WinH, CSIDL_NETHOOD));
FDirs.Add('MyDocuments=' + GetSpecialFolder(WinH, CSIDL_PERSONAL));
FDirs.Add('PrintHood=' + GetSpecialFolder(WinH, CSIDL_PRINTHOOD));
FDirs.Add('Printers=' + GetSpecialFolder(WinH, CSIDL_PRINTERS));
FDirs.Add('Programs=' + GetSpecialFolder(WinH, CSIDL_PROGRAMS));
FDirs.Add('Recent=' + GetSpecialFolder(WinH, CSIDL_RECENT));
FDirs.Add('SendTo=' + GetSpecialFolder(WinH, CSIDL_SENDTO));
FDirs.Add('StartMenu=' + GetSpecialFolder(WinH, CSIDL_STARTMENU));
FDirs.Add('StartUp=' + GetSpecialFolder(WinH, CSIDL_STARTUP));
FDirs.Add('Templates=' + GetSpecialFolder(WinH, CSIDL_TEMPLATES));
s := ReverseStr(FDirs.Values['Desktop']);
s := ReverseStr(Copy(s, Pos('\', s) + 1, 255));
FDirs.Add('Profile=' + s);
GetEnvironment;
end;
procedure TOperatingSystem.Report(var sl: TStringList);
begin
with sl do
begin
Add('[Operating System]');
Add(Format('Platform=%s', [Platform]));
Add(Format('VersionName=%s', [Version]));
Add(Format('Version=%d.%d', [MajorVersion, MinorVersion]));
Add(Format('BuildNumber=%d', [BuildNumber]));
Add(Format('CSD=%s', [CSD]));
Add(Format('SerialNumber=%s', [SerialNumber]));
Add(Format('RegUser=%s', [RegisteredUser]));
Add(Format('RegOrganization=%s', [RegisteredOrg]));
Add('[Environment]');
AddStrings(Environment);
Add('[Folders]');
AddStrings(Folders);
TimeZone.Report(sl);
end;
end;
end.
Jens B
19. august 2003 - 10:18
#13
her :
unit Routines;
interface
uses Windows, Classes;
type
TOSVersion = (osUnknown, os95, os95OSR2, os98, os98SE, osNT3, osNT4, os2K, osME);
PWindow = ^TWindow;
TWindow = record
ClassName,
Text: string;
Handle,
Process,
Thread: longword;
ParentWin,
WndProc,
Instance,
ID,
UserData,
Style,
ExStyle: longint;
Rect,
ClientRect: TRect;
Atom,
ClassBytes,
WinBytes,
ClassWndProc,
ClassInstance,
Background,
Cursor,
Icon,
ClassStyle: longword;
Styles,
ExStyles,
ClassStyles: tstringlist;
Visible: Boolean;
end;
function Bool2YN(b: Boolean): string;
function GetUser: string;
function GetMachine: string;
function GetOS: TOSVersion;
function IsNT: Boolean;
function FormatSeconds(TotalSeconds: comp; WholeSecondsOnly, DisplayAll, DTFormat: Boolean): string;
function ReadRegInfo(ARoot: hkey; AKey, AValue: string): string;
function ReadVerInfo(const fn: string; var Desc: string): string;
function GetClassDevices(AStartKey, AClassName, AValueName: string; var AResult: TStrings): string;
procedure GetEnvironment(EnvList: tstringlist);
function GetWinSysDir: string;
function GetStrFromBuf(Buffer: pchar): string;
function GetWindowInfo(wh: hwnd): PWindow;
function ReplaceStr(ASource, AFind, AReplace: string): string;
function DisplayPropDialog(const Handle: HWND; const FileName: string): Boolean;
procedure StringsToRep(sl: TStrings; CountKwd, ItemKwd: string; var Report: TStringlist);
var
ClassKey: string;
const
DescValue = 'DriverDesc';
implementation
uses
Registry, SysUtils, ShellAPI;
function Bool2YN(b: Boolean): string;
begin
if b then
Result := 'Yes'
else
Result := 'No';
end;
function GetOS;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := osUnknown;
if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
case OS.dwMajorVersion of
3: Result := osNT3;
4: Result := osNT4;
5: Result := os2K;
end;
end
else
begin
if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 0) then
begin
Result := os95;
if (Trim(OS.szCSDVersion) = 'B') then
Result := os95OSR2;
end
else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then
begin
Result := os98;
if (Trim(OS.szCSDVersion) = 'A') then
Result := os98SE;
end
else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) then
Result := osME;
end;
end;
function IsNT: Boolean;
begin
Result := GetOS in [osNT3, osNT4, os2K];
end;
function FormatSeconds(TotalSeconds: comp; WholeSecondsOnly, DisplayAll, DTFormat: Boolean): string;
var
lcenturies, lyears, lmonths, lminutes, lhours, ldays, lweeks: word;
lSecs: Double;
s: array[1..8] of string;
SecondsPerCentury: comp;
FS: string;
begin
if WholeSecondsOnly then
FS := '%.0f'
else
FS := '%.2f';
SecondsPerCentury := 36550 * 24;
SecondsPerCentury := SecondsPerCentury * 3600;
lcenturies := Trunc(TotalSeconds / SecondsPerCentury);
TotalSeconds := TotalSeconds - (lcenturies * SecondsPerCentury);
lyears := Trunc(TotalSeconds / (365.5 * 24 * 3600));
TotalSeconds := TotalSeconds - (lyears * (365.5 * 24 * 3600));
lmonths := Trunc(TotalSeconds / (31 * 24 * 3600));
TotalSeconds := TotalSeconds - (lmonths * (31 * 24 * 3600));
lweeks := Trunc(TotalSeconds / (7 * 24 * 3600));
TotalSeconds := TotalSeconds - (lweeks * (7 * 24 * 3600));
ldays := Trunc(TotalSeconds / (24 * 3600));
TotalSeconds := TotalSeconds - (ldays * (24 * 3600));
lhours := Trunc(TotalSeconds / 3600);
TotalSeconds := TotalSeconds - (lhours * 3600);
lminutes := Trunc(TotalSeconds / 60);
TotalSeconds := TotalSeconds - (lminutes * 60);
if WholeSecondsOnly then
lsecs := Trunc(TotalSeconds)
else
lsecs := TotalSeconds;
if lCenturies = 1 then
s[1] := ' Century, '
else
s[1] := ' Centuries, ';
if lyears = 1 then
s[2] := ' Year, '
else
s[2] := ' Years, ';
if lmonths = 1 then
s[3] := ' Month, '
else
s[3] := ' Months, ';
if lweeks = 1 then
s[4] := ' Week, '
else
s[4] := ' Weeks, ';
if ldays = 1 then
s[5] := ' Day, '
else
s[5] := ' Days, ';
if lhours = 1 then
s[6] := ' Hour, '
else
s[6] := ' Hours, ';
if lminutes = 1 then
s[7] := ' Minute, '
else
s[7] := ' Minutes, ';
if lsecs = 1 then
s[8] := ' Second.'
else
s[8] := ' Seconds.';
if DisplayAll then
begin
if dtformat then
Result := Format('%2.2d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d',
[lyears, lmonths, ldays + lweeks * 7, lhours, lminutes, Round(lSecs)])
else
Result := Format('%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s' + FS + '%s',
[lcenturies, s[1], lyears, s[2], lmonths, s[3], lweeks, s[4], ldays, s[5], lhours, s[6], lminutes, s[7], lSecs, s[8]]);
end
else
begin
if dtformat then
Result := Format('%2.2d:%2.2d:%2.2d',
[lhours, lminutes, Round(lSecs)])
else
begin
if lCenturies >= 1 then
Result := Format('%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s' + FS + '%s',
[lcenturies, s[1], lyears, s[2], lmonths, s[3], lweeks, s[4], ldays, s[5], lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if lyears >= 1 then
Result := Format('%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s' + FS + '%s',
[lyears, s[2], lmonths, s[3], lweeks, s[4], ldays, s[5], lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if lmonths >= 1 then
Result := Format('%.0d%s%.0d%s%.0d%s%.0d%s%.0d%s' + FS + '%s',
[lmonths, s[3], lweeks, s[4], ldays, s[5], lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if lweeks >= 1 then
Result := Format('%.0d%s%.0d%s%.0d%s%.0d%s' + FS + '%s',
[lweeks, s[4], ldays, s[5], lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if ldays >= 1 then
Result := Format('%.0d%s%.0d%s%.0d%s' + FS + '%s',
[ldays, s[5], lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if lhours >= 1 then
Result := Format('%.0d%s%.0d%s' + FS + '%s',
[lhours, s[6], lminutes, s[7], lsecs, s[8]])
else if lminutes >= 1 then
Result := Format('%.0d%s' + FS + '%s', [lminutes, s[7], lsecs, s[8]])
else
Result := Format(FS + '%s', [lsecs, s[8]]);
end;
end;
end;
function ReadRegInfo(ARoot: hkey; AKey, AValue: string): string;
begin
with TRegistry.create do
begin
Result := '';
rootkey := aroot;
if keyexists(akey) then
begin
OpenKey(akey, False);
if ValueExists(avalue) then
begin
case getdatatype(avalue) of
rdstring: Result := ReadString(avalue);
rdinteger: Result := IntToStr(readinteger(avalue));
end;
end;
closekey;
end;
free;
end;
end;
function ReadVerInfo(const fn: string; var Desc: string): string;
var
VersionHandle, VersionSize: dword;
PItem, PVersionInfo: pointer;
FixedFileInfo: PVSFixedFileInfo;
il: uint;
version: string;
p: array[0..MAX_PATH - 1] of char;
begin
version := '';
desc := '';
Result := '';
if fn <> '' then
begin
strpcopy(p, fn);
versionsize := getfileversioninfosize(p, versionhandle);
if versionsize = 0 then
exit;
getMem(pversioninfo, versionsize);
try
if getfileversioninfo(p, versionhandle, versionsize, pversioninfo) then
begin
if VerQueryValue(pversioninfo, '\', pointer(FixedFileInfo), il) then
Version := IntToStr(hiword(FixedFileInfo^.dwfileversionms)) +
'.' + IntToStr(loword(FixedFileInfo^.dwFileVersionMS)) +
'.' + IntToStr(hiword(FixedFileInfo^.dwFileVersionLS)) +
'.' + IntToStr(loword(FixedFileInfo^.dwFileVersionLS));
if VerQueryValue(pversioninfo, pchar('\StringFileInfo\040904E4\FileDescription'), pitem, il) then
desc := pchar(pitem);
end;
finally
freeMem(pversioninfo, versionsize);
Result := version;
end;
end;
end;
function GetMachine: string;
var
n: dword;
buf: pchar;
const
rkMachine = {HKEY_LOCAL_MACHINE\} 'SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName';
rvMachine = 'ComputerName';
begin
n := 255;
buf := stralloc(n);
GetComputerName(buf, n);
Result := strpas(buf);
strdispose(buf);
with TRegistry.Create do
begin
rootkey := HKEY_LOCAL_MACHINE;
if OpenKey(rkMachine, False) then
begin
if ValueExists(rvMachine) then
Result := ReadString(rvMachine);
closekey;
end;
free;
end;
end;
function GetUser: string;
var
n: dword;
buf: pchar;
begin
n := 255;
buf := stralloc(n);
GetUserName(buf, n);
Result := strpas(buf);
strdispose(buf);
end;
function GetClassDevices(AStartKey, AClassName, AValueName: string; var AResult: TStrings): string;
var
i, j: Integer;
sl: TStringList;
s, v, rclass: string;
const
rvGUID = 'ClassGUID';
rvClass = 'Class';
rvLink = 'Link';
begin
Result := '';
AResult.Clear;
with TRegistry.Create do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(AStartKey, False) then
begin
sl := TStringList.Create;
GetKeyNames(sl);
CloseKey;
for i := 0 to sl.Count - 1 do
if OpenKey(AStartKey + '\' + sl[i], False) then
begin
if ValueExists(rvClass) then
begin
rclass := UpperCase(ReadString(rvClass));
if rclass = UpperCase(AClassName) then
begin
if not IsNT then
begin
s := UpperCase(ReadString(rvLink));
CloseKey;
if not OpenKey(AStartKey + '\' + s, False) then
exit;
end
else
s := sl[i];
Result := s;
GetKeyNames(sl);
CloseKey;
for j := 0 to sl.count - 1 do
if OpenKey(AStartKey + '\' + s + '\' + sl[j], False) then
begin
if ValueExists(AValueName) then
begin
v := ReadString(AValueName);
if AResult.IndexOf(v) = -1 then
AResult.Add(v);
end;
CloseKey;
end;
Break;
end;
end;
CloseKey;
end;
sl.free;
end;
free;
end;
end;
procedure GetEnvironment(EnvList: tstringlist);
var
c, i: dword;
b: pchar;
s: string;
begin
EnvList.Clear;
c := 1024;
b := GetEnvironmentStrings;
i := 0;
s := '';
while i < c do
begin
if b[i] <> #0 then
s := s + b[i]
else
begin
if s = '' then
break;
EnvList.Add(s);
s := '';
end;
inc(i);
end;
FreeEnvironmentStrings(b);
end;
function GetWinSysDir: string;
var
n: Integer;
p: PChar;
begin
n := MAX_PATH;
p := stralloc(n);
getwindowsdirectory(p, n);
Result := strpas(p) + ';';
getsystemdirectory(p, n);
Result := Result + strpas(p) + ';';
end;
function GetStrFromBuf(Buffer: pchar): string;
var
i, j: Integer;
begin
Result := '';
j := 0;
i := 0;
repeat
if buffer[i] <> #0 then
begin
Result := Result + buffer[i];
j := 0;
end
else
inc(j);
inc(i);
until j > 1;
end;
function GetWindowInfo(wh: hwnd): PWindow;
var
cn, wn: pchar;
n, wpid, tid: longword;
begin
n := 255;
wn := stralloc(n);
cn := stralloc(n);
tid := GetWindowThreadProcessId(wh, @wpid);
getclassname(wh, cn, n);
getwindowtext(wh, wn, n);
new(Result);
Result^.ClassName := strpas(cn);
Result^.Text := strpas(wn);
Result^.Handle := wh;
Result^.Process := wpid;
Result^.Thread := tid;
Result^.ParentWin := getwindowlong(wh, GWL_HWNDPARENT);
Result^.WndProc := getwindowlong(wh, GWL_WNDPROC);
Result^.Instance := getwindowlong(wh, GWL_HINSTANCE);
Result^.ID := getwindowlong(wh, GWL_ID);
Result^.UserData := getwindowlong(wh, GWL_USERDATA);
Result^.Style := getwindowlong(wh, GWL_STYLE);
Result^.ExStyle := getwindowlong(wh, GWL_EXSTYLE);
getwindowrect(wh, Result^.Rect);
getclientrect(wh, Result^.ClientRect);
Result^.Atom := getclasslong(wh, GCW_ATOM);
Result^.ClassBytes := getclasslong(wh, GCL_CBCLSEXTRA);
Result^.WinBytes := getclasslong(wh, GCL_CBWNDEXTRA);
Result^.ClassWndProc := getclasslong(wh, GCL_WNDPROC);
Result^.ClassInstance := getclasslong(wh, GCL_HMODULE);
Result^.Background := getclasslong(wh, GCL_HBRBACKGROUND);
Result^.Cursor := getclasslong(wh, GCL_HCURSOR);
Result^.Icon := getclasslong(wh, GCL_HICON);
Result^.ClassStyle := getclasslong(wh, GCL_STYLE);
Result^.Styles := tstringlist.create;
Result^.visible := iswindowvisible(wh);
if not (Result^.ExStyle and WS_BORDER = 0) then
Result^.Styles.add('WS_BORDER');
if not (Result^.Style and WS_CHILD = 0) then
Result^.Styles.add('WS_CHILD');
if not (Result^.Style and WS_CLIPCHILDREN = 0) then
Result^.Styles.add('WS_CLIPCHILDREN');
if not (Result^.Style and WS_CLIPSIBLINGS = 0) then
Result^.Styles.add('WS_CLIPSIBLINGS');
if not (Result^.Style and WS_DISABLED = 0) then
Result^.Styles.add('WS_DISABLED');
if not (Result^.Style and WS_DLGFRAME = 0) then
Result^.Styles.add('WS_DLGFRAME');
if not (Result^.Style and WS_GROUP = 0) then
Result^.Styles.add('WS_GROUP');
if not (Result^.Style and WS_HSCROLL = 0) then
Result^.Styles.add('WS_HSCROLL');
if not (Result^.Style and WS_MAXIMIZE = 0) then
Result^.Styles.add('WS_MAXIMIZE');
if not (Result^.Style and WS_MAXIMIZEBOX = 0) then
Result^.Styles.add('WS_MAXIMIZEBOX');
if not (Result^.Style and WS_MINIMIZE = 0) then
Result^.Styles.add('WS_MINIMIZE');
if not (Result^.Style and WS_MINIMIZEBOX = 0) then
Result^.Styles.add('WS_MINIMIZEBOX');
if not (Result^.Style and WS_OVERLAPPED = 0) then
Result^.Styles.add('WS_OVERLAPPED');
if not (Result^.Style and WS_POPUP = 0) then
Result^.Styles.add('WS_POPUP');
if not (Result^.Style and WS_SYSMENU = 0) then
Result^.Styles.add('WS_SYSMENU');
if not (Result^.Style and WS_TABSTOP = 0) then
Result^.Styles.add('WS_TABSTOP');
if not (Result^.Style and WS_THICKFRAME = 0) then
Result^.Styles.add('WS_THICKFRAME');
if not (Result^.Style and WS_VISIBLE = 0) then
Result^.Styles.add('WS_VISIBLE');
if not (Result^.Style and WS_VSCROLL = 0) then
Result^.Styles.add('WS_VSCROLL');
Result^.ExStyles := tstringlist.create;
if not (Result^.ExStyle and WS_EX_ACCEPTFILES = 0) then
Result^.ExStyles.add('WS_EX_ACCEPTFILES');
if not (Result^.ExStyle and WS_EX_DLGMODALFRAME = 0) then
Result^.ExStyles.add('WS_EX_DLGMODALFRAME');
if not (Result^.ExStyle and WS_EX_NOPARENTNOTIFY = 0) then
Result^.ExStyles.add('WS_EX_NOPARENTNOTIFY');
if not (Result^.ExStyle and WS_EX_TOPMOST = 0) then
Result^.ExStyles.add('WS_EX_TOPMOST');
if not (Result^.ExStyle and WS_EX_TRANSPARENT = 0) then
Result^.ExStyles.add('WS_EX_TRANSPARENT');
if not (Result^.ExStyle and WS_EX_MDICHILD = 0) then
Result^.ExStyles.add('WS_EX_MDICHILD');
if not (Result^.ExStyle and WS_EX_TOOLWINDOW = 0) then
Result^.ExStyles.add('WS_EX_TOOLWINDOW');
if not (Result^.ExStyle and WS_EX_WINDOWEDGE = 0) then
Result^.ExStyles.add('WS_EX_WINDOWEDGE');
if not (Result^.ExStyle and WS_EX_CLIENTEDGE = 0) then
Result^.ExStyles.add('WS_EX_CLIENTEDGE');
if not (Result^.ExStyle and WS_EX_CONTEXTHELP = 0) then
Result^.ExStyles.add('WS_EX_CONTEXTHELP');
if not (Result^.ExStyle and WS_EX_RIGHT = 0) then
Result^.ExStyles.add('WS_EX_RIGHT')
else
Result^.ExStyles.add('WS_EX_LEFT');
if not (Result^.ExStyle and WS_EX_RTLREADING = 0) then
Result^.ExStyles.add('WS_EX_RTLREADING')
else
Result^.ExStyles.add('WS_EX_LTRREADING');
if not (Result^.ExStyle and WS_EX_LEFTSCROLLBAR = 0) then
Result^.ExStyles.add('WS_EX_LEFTSCROLLBAR')
else
Result^.ExStyles.add('WS_EX_RIGHTSCROLLBAR');
if not (Result^.ExStyle and WS_EX_CONTROLPARENT = 0) then
Result^.ExStyles.add('WS_EX_CONTROLPARENT');
if not (Result^.ExStyle and WS_EX_STATICEDGE = 0) then
Result^.ExStyles.add('WS_EX_STATICEDGE');
if not (Result^.ExStyle and WS_EX_APPWINDOW = 0) then
Result^.ExStyles.add('WS_EX_APPWINDOW');
Result^.ClassStyles := tstringlist.create;
if not (Result^.ClassStyle and CS_BYTEALIGNCLIENT = 0) then
Result^.ClassStyles.add('CS_BYTEALIGNCLIENT');
if not (Result^.ClassStyle and CS_VREDRAW = 0) then
Result^.ClassStyles.add('CS_VREDRAW');
if not (Result^.ClassStyle and CS_HREDRAW = 0) then
Result^.ClassStyles.add('CS_HREDRAW');
if not (Result^.ClassStyle and CS_KEYCVTWINDOW = 0) then
Result^.ClassStyles.add('CS_KEYCVTWINDOW');
if not (Result^.ClassStyle and CS_DBLCLKS = 0) then
Result^.ClassStyles.add('CS_DBLCLKS');
if not (Result^.ClassStyle and CS_OWNDC = 0) then
Result^.ClassStyles.add('CS_OWNDC');
if not (Result^.ClassStyle and CS_CLASSDC = 0) then
Result^.ClassStyles.add('CS_CLASSDC');
if not (Result^.ClassStyle and CS_PARENTDC = 0) then
Result^.ClassStyles.add('CS_PARENTDC');
if not (Result^.ClassStyle and CS_NOKEYCVT = 0) then
Result^.ClassStyles.add('CS_NOKEYCVT');
if not (Result^.ClassStyle and CS_NOCLOSE = 0) then
Result^.ClassStyles.add('CS_NOCLOSE');
if not (Result^.ClassStyle and CS_SAVEBITS = 0) then
Result^.ClassStyles.add('CS_SAVEBITS');
if not (Result^.ClassStyle and CS_BYTEALIGNWINDOW = 0) then
Result^.ClassStyles.add('CS_BYTEALIGNWINDOW');
if not (Result^.ClassStyle and CS_GLOBALCLASS = 0) then
Result^.ClassStyles.add('CS_GLOBALCLASS');
strdispose(wn);
strdispose(cn);
end;
function ReplaceStr;
var
p: Integer;
begin
Result := '';
p := pos(uppercase(AFind), uppercase(ASource));
while p > 0 do
begin
Result := Result + Copy(ASource, 1, p - 1) + AReplace;
Delete(ASource, 1, p + Length(AFind) - 1);
p := pos(uppercase(AFind), uppercase(ASource));
end;
Result := Result + ASource;
end;
function DisplayPropDialog(const Handle: HWND; const FileName: string): Boolean;
var
Info: TShellExecuteInfo;
begin
FillChar(Info, SizeOf(Info), #0);
with Info do
begin
cbSize := SizeOf(Info);
lpFile := PChar(FileName);
nShow := SW_SHOW;
fMask := SEE_MASK_INVOKEIDLIST;
Wnd := Handle;
lpVerb := PChar('properties');
end;
Result := ShellExecuteEx(@Info);
end;
procedure StringsToRep(sl: TStrings; CountKwd, ItemKwd: string; var Report: TStringlist);
var
i: Integer;
begin
with Report do
begin
Add(Format('%s=%d', [CountKwd, sl.Count]));
for i := 0 to sl.Count - 1 do
Add(Format('%s%d=%s', [ItemKwd, i + 1, sl[i]]));
end;
end;
end.