Installer date time limit

From ISXKB

Revision as of 21:49, 1 July 2007 by Markus (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

The function GetLocalTime () retrieves the current local date and time in a structure SYSTEMTIME. With this information it is possibile to compare the retrieved date with a known date/time structure to disallow the installation after a particular date.

[Setup]
AppName=DateTimeStop
AppVerName=DateTimeStop
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=true
DisableProgramGroupPage=true
DefaultDirName={pf}\DateTimeStop
DisableStartupPrompt=true

[Code]
type
  TSystemTime = record
    wYear : Word;
    wMonth : Word;
    wDayOfWeek : Word;
    wDay : Word;
    wHour : Word;
    wMinute : Word;
    wSecond : Word;
    wMilliseconds : Word;
  end;


procedure GetLocalTime(var lpSystemTime: TSystemTime);
 external 'GetLocalTime@kernel32.dll';

//
// compare dt1 and dt2, return false id dt1 is lower than dt2
// thanks to Bruno Gellweiler that provide a working function :)

function IsOKDateTime( dt1, dt2: TSystemTime ) : Boolean;
begin
    Result := true;
    if dt2.wYear < dt1.wYear then
        result := false
    else if dt2.wYear = dt1.wYear then
        if dt2.wMonth < dt1.wMonth then
            result := false
        else if dt2.wMonth = dt1.wMonth then
            if dt2.wDay < dt1.wDay then
                result := false ;
end;


function InitializeSetup: Boolean;
var
  lt, datelimit: TSystemTime;
  s, crlf: string;

begin

  crlf := #13#10;

  // let's say it is not allowed to install after 1 May 2006
  datelimit.wYear := 2006;
  datelimit.wMonth := 5;
  datelimit.wDay := 1;

  GetLocalTime(lt);

  Result := IsOKDateTime( lt, datelimit );

  s := 'Install time limit, it is not possible to install this program.';

  if not Result then
  	// just to show datetime infos
  	MsgBox( s , mbError, MB_OK );
end;

See Also

External Links

Personal tools
Ads: