Installer date time limit

From ISXKB

(Difference between revisions)
Jump to: navigation, search

Vincenzo (Talk | contribs)
(Installer date time limit)
Newer edit →

Revision as of 15:24, 22 January 2007

GetLocalTime function retrieves the current local date and time in SYSTEMTIME structure, it is possibile to compare these data with a known date time structure to stop installation after a 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;
Personal tools
Ads: