Page 1 of 1

Time when the file was compiled

Posted: Fri Oct 16, 2020 7:19 am
by kvitaliy
There are no checks For the validity of the exe file!

Code: Select all

Procedure.s Time_Date_Stamp(FileExe.s)
If ReadFile(0, FileExe)
  FileSeek(0,60) ; IMAGE_NT_SIGNATURE
  FileSeek(0,ReadCharacter(0)+8) ; TimeDateStamp
  ProcedureReturn FormatDate("%dd/%mm/%yyyy %hh:%ii:%ss",ReadLong(0)) + " (GMT)"
EndIf
ProcedureReturn ""
EndProcedure

; Test

File.s = "C:\Windows\SysWOW64\calc.exe";ProgramFilename()
tds$ = Time_Date_Stamp(File)
If tds$
  MessageRequester("Ok","File creation time: " + tds$)
Else
  MessageRequester("Error",File + " -> File Not found")
EndIf

Re: Time when the file was compiled

Posted: Fri Oct 16, 2020 9:30 am
by BarryG
Is this reliable? Both files below exist on my PC but look at the return values. One is all zeros, and the other is in the future (year 2022):

Code: Select all

Procedure.s Time_Date_Stamp(FileExe.s)
  If ReadFile(0, FileExe)
    FileSeek(0,60) ; IMAGE_NT_SIGNATURE
    FileSeek(0,ReadCharacter(0)+8) ; TimeDateStamp
    ProcedureReturn FormatDate("%dd/%mm/%yyyy %hh:%ii:%ss",ReadLong(0)) + " (GMT)"
  EndIf
  ProcedureReturn ""
EndProcedure

; Test

Debug Time_Date_Stamp("C:\Windows\SysWOW64\calc.exe") ; 00/00/0000 00:00:00 (GMT)
Debug Time_Date_Stamp("C:\Program Files\Internet Explorer\iexplore.exe") ; 20/04/2022 19:38:41 (GMT)

Re: Time when the file was compiled

Posted: Fri Oct 16, 2020 9:53 am
by Mindphazer
BarryG wrote:and the other is in the future (year 2022):
Marty McFly ? Are you here ??

Re: Time when the file was compiled

Posted: Fri Oct 16, 2020 11:11 am
by kvitaliy
BarryG wrote:Is this reliable? Both files below exist on my PC but look at the return values. One is all zeros, and the other is in the future (year 2022)
There is no guarantee for other files.
But you will definitely define the files compiled by PureBasic!

Re: Time when the file was compiled

Posted: Fri Oct 16, 2020 11:19 am
by NicTheQuick
Please change the code to use #PB_Any and close the file again. Otherwise there are bad things than can happen.

Re: Time when the file was compiled

Posted: Fri Oct 16, 2020 10:34 pm
by Tenaja
If you want compile timestamp, then use the constant, not the function.

Re: Time when the file was compiled

Posted: Sat Oct 17, 2020 1:31 am
by BarryG
kvitaliy wrote:There is no guarantee for other files.
But you will definitely define the files compiled by PureBasic!
You confused me by using an example file of "C:\Windows\SysWOW64\calc.exe" in your first post.