Get a files last updated time using pascal (innosetup)

丶灬走出姿态 提交于 2020-01-11 11:51:35

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/749954/get-a-files-last-updated-time-using-pascal-innosetup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!