File Creation Date, Last Modified Date, Last Accessed Date

Just starting out? Need help? Post your questions and find answers here.
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

File Creation Date, Last Modified Date, Last Accessed Date

Post by whizza »

Hi,

Using PB, is there a way to examine and change a files Creation Date, Last Modified Date, Last Accessed Date?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post by Josh »

GetFileDate()
SetFileDate()

Be careful on Linux and OSX. See remarks in Help.
Last edited by Josh on Tue Mar 10, 2020 11:52 am, edited 1 time in total.
sorry for my bad english
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post by whizza »

Thank you Josh.
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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)
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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

Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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))
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 3996
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: File Creation Date, Last Modified Date, Last Accessed Da

Post 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.
sorry for my bad english
whizza
User
User
Posts: 46
Joined: Tue Nov 13, 2007 4:41 pm
Location: England

Re: File Creation Date, Last Modified Date, Last Accessed Da

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

Re: File Creation Date, Last Modified Date, Last Accessed Da

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