Archive: Where is SetFileTime?


Where is SetFileTime?
I need to update the filetime of a file that is already installed (and will not be updated) during my installation.

Now I found GetFileTime in the NSIS documentation, but not one word on any SetFileTime :(

I could add that function to the source somehow most probably, but would like to hear first if there are any existing solutions for this? Thanks :)


There is no built in command for that. If you want to change the modified time to the current time you can use this little script:

FileOpen $0 "C:\path\to\file" a
FileSeek $0 0 SET
FileReadByte $0 $1
FileSeek $0 0 SET
FileWriteByte $0 $1
FileClose $0

If you want to set it to another time you can use the System.dll plug-in and call SetFileTime directly.


No, I need a specific date - that of the installer.

So I tried:

FileOpen $0 $EXEDIR\myinstaller.exe a
System::Call 'kernel32::GetFileTime(i, i, i, i) v (.r0, .r1, .r2, .r3)'
FileClose $0
FileOpen $0 $INSTDIR\mydatefile.zip a
System::Call 'kernel32::SetFileTime(i, *i, *i, *i) v (.r0, .r1, .r2, .r3)'
FileClose $0
Actually I would have to set a special date instead of the one from the installer, but if it doesn't even work this way, I'll have to look for some other way to go avoid this :(

There are a few problems in that script:


Here's a working script:

FileOpen $0 $EXEDIR\bla.exe r
System::Call 'kernel32::GetFileTime(i, *l, *l, *l) i (r0, .r1, .r2, .r3)'
FileClose $0
FileOpen $0 $EXEDIR\uninst.exe a
System::Call 'kernel32::SetFileTime(i, *l, *l, *l) i (r0, r1, r2, r3)'
FileClose $0

Ok, I admit, I didn't fully understand System:Call (obviously) ;)

Thanks a lot for the working script!


Is it possible to do that during script compile time?

EDIT: nvm I found my answer