Get a files last updated time using pascal (innosetup)

前端 未结 2 1869
鱼传尺愫
鱼传尺愫 2021-01-25 13:33

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

相关标签:
2条回答
  • 2021-01-25 14:14

    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.

    0 讨论(0)
  • 2021-01-25 14:22

    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

    0 讨论(0)
提交回复
热议问题