Time when the file was compiled

Share your advanced PureBasic knowledge/code with the community.
kvitaliy
Enthusiast
Enthusiast
Posts: 162
Joined: Mon May 10, 2010 4:02 pm

Time when the file was compiled

Post 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
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: Time when the file was compiled

Post 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)
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Time when the file was compiled

Post by Mindphazer »

BarryG wrote:and the other is in the future (year 2022):
Marty McFly ? Are you here ??
MacBook Pro 14" M1 Pro - 16 Gb - MacOS 14 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
kvitaliy
Enthusiast
Enthusiast
Posts: 162
Joined: Mon May 10, 2010 4:02 pm

Re: Time when the file was compiled

Post 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!
User avatar
NicTheQuick
Addict
Addict
Posts: 1227
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Time when the file was compiled

Post by NicTheQuick »

Please change the code to use #PB_Any and close the file again. Otherwise there are bad things than can happen.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Time when the file was compiled

Post by Tenaja »

If you want compile timestamp, then use the constant, not the function.
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: Time when the file was compiled

Post 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.
Post Reply