Page 1 of 1
File Creation Date, Last Modified Date, Last Accessed Date
Posted: Tue Mar 10, 2020 10:09 am
by whizza
Hi,
Using PB, is there a way to examine and change a files Creation Date, Last Modified Date, Last Accessed Date?
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 10:27 am
by Josh
GetFileDate()
SetFileDate()
Be careful on Linux and OSX. See remarks in Help.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 11:49 am
by whizza
Thank you Josh.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 12:19 pm
by whizza
I'm trying to set the #PB_Date_Modified of the running exe to when exe was launched but it doesn't appear to be working.
Is this due to Windows permissions or because the exe file is open for it to be executed ?
Code: Select all
Global LaunchToD = Date()
Global LaunchExE$ = ProgramFilename()
Global LMDate1 = GetFileDate(LaunchExE$, #PB_Date_Modified)
Global LMDate2 = SetFileDate(LaunchExE$, #PB_Date_Modified, LaunchToD)
Global LMDate3 = GetFileDate(LaunchExE$, #PB_Date_Modified)
MessageRequester("LMDate", Str(LaunchToD) + " " + Str(LMDate1) + " " + Str(LMDate2) + " " + Str(LMDate3))
Using Win10x64 PB572b2x64
I get same result using #PB_Date_Accessed. What operations would make Windows update #PB_Date_Accessed on an exe file? Launching the exe doesn't appear to update it.
Renaming the exe updates #PB_Date_Accessed
Code: Select all
Global LaunchExE$ = ProgramFilename()
Global LADate1 = GetFileDate(LaunchExE$, #PB_Date_Accessed)
Global LMDate1 = GetFileDate(LaunchExE$, #PB_Date_Modified)
RenameFile(LaunchExE$, LaunchExE$ + ".tmp")
RenameFile(LaunchExE$ + ".tmp", LaunchExE$)
Global LADate2 = GetFileDate(LaunchExE$, #PB_Date_Accessed)
Global LMDate2 = GetFileDate(LaunchExE$, #PB_Date_Modified)
MessageRequester("LMDate", "LA "+ Str(LADate1) + " " + Str(LADate2) + " LM " + Str(LMDate1) + " " + Str(LMDate2))
Extract from
https://docs.microsoft.com/en-us/window ... l-behavior
disablelastaccess {1|0} Disables (1) or enables (0) updates to the Last Access Time stamp on each directory when directories are listed on an NTFS volume. You must restart your computer for this parameter to take effect.
C:\windows\system32> fsutil behavior query disablelastaccess
DisableLastAccess = 0 (User Managed, Disabled)
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 4:39 pm
by whizza
Set the #PB_Date_Modified of the running exe file to when exe was launched.
Not very elegant, but it works. Is there a better solution?
Code: Select all
Global LaunchExE$ = ProgramFilename()
Global ExEBytes.q = FileSize(LaunchExE$)
Global LMDate = GetFileDate(LaunchExE$, #PB_Date_Modified)
MessageRequester("LMDate", Str(LMDate))
If ReadFile(0, LaunchExE$, #PB_File_SharedRead)
DeleteFile(LaunchExE$+".del")
OpenFile(1, LaunchExE$+".tmp")
For Bytes = 1 To ExEBytes
Byte.b = ReadByte(0)
WriteByte(1, Byte)
Next Bytes
CloseFile(0)
CloseFile(1)
RenameFile(LaunchExE$, LaunchExE$+".del")
RenameFile(LaunchExE$+".tmp", LaunchExE$)
SetFileAttributes(LaunchExE$+".del", #PB_FileSystem_Hidden)
Else
MessageRequester("Error", "Cannot open " + LaunchExE$)
EndIf
End
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 5:42 pm
by Marc56us
whizza wrote:I'm trying to set the #PB_Date_Modified of the running exe to when exe was launched but it doesn't appear to be working.
Is this due to Windows permissions or because the exe file is open for it to be executed ?
Code: Select all
Global LaunchToD = Date()
Global LaunchExE$ = ProgramFilename()
Global LMDate1 = GetFileDate(LaunchExE$, #PB_Date_Modified)
Global LMDate2 = SetFileDate(LaunchExE$, #PB_Date_Modified, LaunchToD)
Global LMDate3 = GetFileDate(LaunchExE$, #PB_Date_Modified)
MessageRequester("LMDate", Str(LaunchToD) + " " + Str(LMDate1) + " " + Str(LMDate2) + " " + Str(LMDate3))
You
set file date but not
read result
SetFileDate() Returns nonzero if the operation was successful and zero otherwise, not the new date.
Code: Select all
Global LaunchToD = Date()
Global LaunchExE$ = ProgramFilename()
Global LMDate1 = GetFileDate(LaunchExE$, #PB_Date_Modified)
; ----------------------------------------------------------------------
; Global LMDate2 = SetFileDate(LaunchExE$, #PB_Date_Modified, LaunchToD)
SetFileDate(LaunchExE$, #PB_Date_Modified, LaunchToD)
Global LMDate2 = GetFileDate(LaunchExE$, #PB_Date_Modified)
; ----------------------------------------------------------------------
Global LMDate3 = GetFileDate(LaunchExE$, #PB_Date_Modified)
MessageRequester("LMDate", Str(LaunchToD) + " " + Str(LMDate1) + " " + Str(LMDate2) + " " + Str(LMDate3))
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 8:24 pm
by whizza
Thanks Marc56us but I'm storing the result of SetFileDate() in LMDate2 and the result is zero.
I did produce exe from your version of code, but SetFileDate() still did not change the date stamp on exe file.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 11:15 pm
by skywalk
What is the reason to modify your exe timestamps?
Is it for licensing purposes?
If the exe is installed to a protected folder, you will not have access to modify unless run as admin.
If the exe is installed to a user defined folder, then maybe.
To upgrade my MyApp.exe, I trigger a self-created batch file to run with runprogram(), then immediately close MyApp.exe. At this point, you can modify, upgrade or whatever. Upon completion, the batch file restarts MyApp.exe.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Tue Mar 10, 2020 11:57 pm
by BarryG
whizza wrote:SetFileDate() still did not change the date stamp on exe file.
You can't write to an open file (meaning a running exe can't write to itself); that's why skywalk has to use a batch file to do it.
Also, are you taking into account that the user may have set the exe file to read-only, to prevent changes? Or that they can use a simple batch file to always run the same original unmodified exe? As you can see in the simple batch file below, the user has copied the original unmodified exe (assume it's called "MyApp.exe") as a
new file called "OriginalUnmodified.exe". Then, the batch file simply copies that new file to a name of "CopyOfModded.exe", and
this is what gets run. If your app tries to change the date stamp of itself (which is "CopyOfModded.exe"), who cares? The changes to "CopyOfUnmodded.exe" will be gone with the next batch run.
Code: Select all
del CopyOfUnmodded.exe
copy OriginalUnmodified.exe CopyOfUnmodded.exe
CopyOfUnmodded.exe
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Wed Mar 11, 2020 12:39 am
by Josh
The question that comes to mind is why someone would want to change the date of the own exe. Looking at the other questions from whizza, I have a slight suspicion that it could be a scriptkiddie.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Wed Mar 11, 2020 12:12 pm
by whizza
Josh, I can assure you I'm not. True I do not have much experience of programming for Windows os but I'm not a hacker.
I'm just looking for a method to ensure that the exe only runs once per day but I do not want to use any additional files or the registry to keep track of this.
Re: File Creation Date, Last Modified Date, Last Accessed Da
Posted: Wed Mar 11, 2020 12:18 pm
by BarryG
whizza wrote:I'm just looking for a method to ensure that the exe only runs once per day
You literally can't stop that at all; especially not by writing the use to the exe. My batch file trick would put an end to that immediately.