1

In the uninstall portion of an innosetup script, I'd like to add a check to see if a specific file's last update datetime occured within the last 10 mins.

Does anyone know the innosetup compatable pascal code for this?

Jonik
  • 80,077
  • 70
  • 264
  • 372
monkut
  • 42,176
  • 24
  • 124
  • 155

2 Answers2

6

You can use the Windows API function GetFileAttributesEx to get the last modification date. Putting this in your [CODE] section should work:

const
    GetFileExInfoStandard = $0;

type 
    FILETIME = record 
      LowDateTime:  DWORD; 
      HighDateTime: DWORD; 
    end; 

    WIN32_FILE_ATTRIBUTE_DATA = record 
      FileAttributes: DWORD; 
      CreationTime:   FILETIME; 
      LastAccessTime: FILETIME; 
      LastWriteTime:  FILETIME; 
      FileSizeHigh:   DWORD; 
      FileSizeLow:    DWORD; 
    end; 

    SYSTEMTIME = record 
      Year:         WORD; 
      Month:        WORD; 
      DayOfWeek:    WORD; 
      Day:          WORD; 
      Hour:         WORD; 
      Minute:       WORD; 
      Second:       WORD; 
      Milliseconds: WORD; 
    end; 

function GetFileAttributesEx (
    FileName:            string;  
    InfoLevelId:         DWORD; 
    var FileInformation: WIN32_FILE_ATTRIBUTE_DATA
    ): Boolean; 
external 'GetFileAttributesExA@kernel32.dll stdcall'; 

function FileTimeToSystemTime(
    FileTime:        FILETIME; 
    var SystemTime:  SYSTEMTIME
    ): Boolean; 
external 'FileTimeToSystemTime@kernel32.dll stdcall'; 

You can test it by modifying the InitializeWizard function of your installer project like this:

procedure InitializeWizard();
    var 
      FileInformation: WIN32_FILE_ATTRIBUTE_DATA; 
      SystemInfo: SYSTEMTIME;     
begin
    GetFileAttributesEx(
        'c:\ntldr', 
        GetFileExInfoStandard , 
        FileInformation); 

    FileTimeToSystemTime(
        FileInformation.LastWriteTime, 
        SystemInfo); 

    MsgBox(
        format(
            '%4.4d-%2.2d-%2.2d', 
            [SystemInfo.Year, SystemInfo.Month, SystemInfo.Day]),
        mbInformation, MB_OK);
end;

On my system (XP SP3), the messagebox says: 2008-08-04

none
  • 4,669
  • 14
  • 62
  • 102
Treb
  • 19,903
  • 7
  • 54
  • 87
0

At the moment the only way to support this would be to use a DLL and link it to your uninstall.

You will have to write the DLL that has the functionality your want.

The default INNOSetup install has examples showing you how to call DLLs. After that it should be simple.

As long as you can write a DLL.

HTH, Ryan.

Vivian Mills
  • 2,552
  • 14
  • 19