Installation date and time in registry

From ISXKB

Revision as of 14:57, 11 October 2007 by Markus (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

This example shows how to use the Windows API functions GetSystemTime () and GetLocalTime (). It displays a message box with the current system time and the current local time and then stores the local time in the registry.

This is a modifed version of the original article from Vincenzo in the old Inno Setup Extended Knowledgebase Isxkbchm.zip.

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

[Registry]
Root: HKLM; Subkey: Software\MyCompany\MyProgram; ValueType: string; ValueName: DateTimeInstall; ValueData: {code:GetMyRegistryValue|''}

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

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

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

var
  // Variable to store date time.
  st, lt: TSystemTime;

function FormatDateTime( dt: TSystemTime ) : String;
var
  s: String;
begin
  s := IntToStr (dt.wMonth);
  if (length (s) < 2) then s:= '0' + s;
  Result := IntToStr (dt.wYear) + '-' + s;
  s := IntToStr (dt.wDay);
  if (length (s) < 2) then s:= '0' + s;
  Result := Result + '-' + s;
  s := IntToStr (dt.wHour);
  if (length (s) < 2) then s:= '0' + s;
  Result := Result + ' ' + s;
  s := IntToStr (dt.wMinute);
  if (length (s) < 2) then s:= '0' + s;
  Result := Result + ':' + s;
  s := IntToStr (dt.wSecond);
  if (length (s) < 2) then s:= '0' + s;
  Result := Result + ':' + s;
end;

function GetMyRegistryValue (s : String ) : String;
begin
	Result := FormatDateTime (lt);
end;

function InitializeSetup: Boolean;
var
  s, crlf: String;

begin
  crlf := #13#10;

  GetSystemTime(st);
  GetLocalTime(lt);

  s := 'System Time is: ' + crlf +
       FormatDateTime (st) + crlf + crlf +
       'Local Time is:  ' + crlf +
       FormatDateTime (lt);

  // Display what we've retrieved.
  MsgBox (s, mbInformation, MB_OK);

  Result := true;
end;

See also

External links

Personal tools
Ads: