File Creation Date, Last Modified Date, Last Accessed Date
File Creation Date, Last Modified Date, Last Accessed Date
Hi,
Using PB, is there a way to examine and change a files Creation Date, Last Modified Date, Last Accessed Date?
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
GetFileDate()
SetFileDate()
Be careful on Linux and OSX. See remarks in Help.
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
Re: File Creation Date, Last Modified Date, Last Accessed Da
Thank you Josh.
Re: File Creation Date, Last Modified Date, Last Accessed Da
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 ?
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
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)
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))
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
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?
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
You set file date but not read resultwhizza 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))
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
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.
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
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.
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
Re: File Creation Date, Last Modified Date, Last Accessed Da
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.whizza wrote:SetFileDate() still did not change the date stamp on exe file.
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
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
Re: File Creation Date, Last Modified Date, Last Accessed Da
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.
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
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.whizza wrote:I'm just looking for a method to ensure that the exe only runs once per day