Share your advanced PureBasic knowledge/code with the community.
kvitaliy
Enthusiast
Posts: 162 Joined: Mon May 10, 2010 4:02 pm
Post
by kvitaliy » Fri Oct 16, 2020 7:19 am
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
Posts: 3331 Joined: Thu Apr 18, 2019 8:17 am
Post
by BarryG » Fri Oct 16, 2020 9:30 am
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)
Mindphazer
Enthusiast
Posts: 346 Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie
Post
by Mindphazer » Fri Oct 16, 2020 9:53 am
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
Posts: 162 Joined: Mon May 10, 2010 4:02 pm
Post
by kvitaliy » Fri Oct 16, 2020 11:11 am
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!
NicTheQuick
Addict
Posts: 1227 Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:
Post
by NicTheQuick » Fri Oct 16, 2020 11:19 am
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.
Tenaja
Addict
Posts: 1949 Joined: Tue Nov 09, 2010 10:15 pm
Post
by Tenaja » Fri Oct 16, 2020 10:34 pm
If you want compile timestamp, then use the constant, not the function.
BarryG
Addict
Posts: 3331 Joined: Thu Apr 18, 2019 8:17 am
Post
by BarryG » Sat Oct 17, 2020 1:31 am
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.