function
GetWindowsInstallationDate():TDate;
var
Reg : TRegistry ;
StartDate : TDate; //12:00 A.M. on January 1, 1970
begin
Reg := TRegistry.Create ;
try
Reg.RootKey := HKEY_LOCAL_MACHINE ;
If Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion',
False) then
begin
StartDate := EncodeDateTime(1970,1,1,0,0,0,0);
Result := IncSecond(StartDate,Reg.ReadInteger('InstallDate'));
end else
begin
messagedlg('This information is not available on this
Operating System',mtError,[mbOK],0);
exit;
end;
finally
Reg.Free;
end;
end;
function GetWindowsLife(InstallDate
: TDate): String;
const
SecsPerDay : Integer = 60 * 60 * 24;
SecsPerHour : Integer = 60 * 60;
SecsPerMinute : Integer = 60;
SecsPerSecond : Integer = 1;
var
TimeDiff, Days, Hours, Minutes, Seconds : Integer;
begin
TimeDiff := SecondsBetween(Now,InstallDate);
Days := TimeDiff div SecsPerDay;
Dec(TimeDiff, Days * SecsPerDay);
Hours := TimeDiff div SecsPerhour;
Dec(TimeDiff, Hours * SecsPerhour);
Minutes := TimeDiff div SecsPerminute;
Dec(TimeDiff, Minutes * SecsPerminute);
Seconds := TimeDiff div SecsPerSecond;
Result := Format('%d Days %d Hours %d Minutes %d Seconds',[Days, Hours,
Minutes, Seconds]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := 'Install Date: ' +
DateTimeToStr(GetWindowsInstallationDate);
Label2.Caption := 'Windows LifeTime: ' +
GetWindowsLife(GetWindowsInstallationDate);
end; |