Preserving "Last Accessed" Datestamp In Shortcuts Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 20 Mar 2021, 19:58

I'm not sure if it's Windows 10 acting weird, or if I'm doing this incorrectly. I'd like to check the "Last Accessed" time of a shortcut file (.lnk) and keep that time intact while I "access" the shortcut to get its target and icon. Not sure what's going on, is it that checking the access timestamp has to "access" the shortcut to get it? Here's a minimal example of the idea:

Code: Select all

FileGetTime, LastAccessedTimeRaw, someShortcut.lnk, A ; gets "last accessed" date/time
FileGetShortcut, someShortcut.lnk, ShortcutTarget
FileSetTime, LastAccessedTimeRaw, someShortcut.lnk, A ; replaces "last accessed" date/time
That's the idea, keeping it intact. I'm using a loop to get all the shortcuts from the desktop, but not sure why it's not working, here is the part of my code I'm using:

Code: Select all

Gui, 2: Add, ListView, x40 y130 h146 w380 Checked +ReadOnly +Sort vList1, Shortcut to Clean Up                                 |Date Last Used
Loop, %A_Desktop%\*.lnk
{
	FileGetTime, LastAccessedTimeRaw, %A_LoopFileFullPath%, A
	FileGetShortcut, %A_LoopFileFullPath%, ShortcutTarget
	SplitPath, A_LoopFileFullPath,,,, OutNameNoExt
	if !FileExist(ShortcutTarget)
	{
		LV_Add("Check", OutNameNoExt, "No Target")
		continue
	}

	FormatTime, LastAccessedTimeFormatted, %LastAccessedTimeRaw%, M`/dd`/yyyy  h`:mm`.ss tt
	LV_Add(Checkbox, OutNameNoExt, LastAccessedTimeFormatted)
	InitialShortcutsFound = %A_Index%
	
	FileSetTime, LastAccessedTimeRaw, %A_LoopFileFullPath%, A
}
Gui, 2: Show, w500 h360, Desktop Cleanup Wizard
Results: seems like running this on shortcuts still changes it's "Last Accessed" stamp but only sometimes? Unsure what to think.
Last edited by WeedTrek on 21 Mar 2021, 17:26, edited 1 time in total.
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by mikeyww » 20 Mar 2021, 20:30

Since accessing a file would update the last access, I imagine that you want to disable the update. In Windows, the following command can do that.

Code: Select all

fsutil behavior set disablelastaccess [0 or 1]
Restarting the computer may be needed to implement the change.

I'm not sure if there are other ways.
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 20 Mar 2021, 21:25

So that's kind of the equivalent of a registry change, I'd like to avoid that if possible as I hate "intruding" on anyone's computer to make arbitrary changes in the way their Windows deals with every shortcut from that point onwards. I would assume that being able to set that last accessed time would actually leave that time in the shortcut for the next instance of checking.
I could do that programatically (the windows cmd thing) but I'd be presuming the user hasn't set that to 1 already and I'd be setting it back to 0, potentially interfering with whatever they're doing which requires that. And if it requires restarting the computer to get that far it's defeating the point entirely :)
Thanks mikeyww... I learned something new about Windows I never knew before, that's cool.
In Windows XP, its desktop cleanup wizard gets the last accessed time of shortcuts without changing it at all, maybe there's a Windows command that temporarily disables write access to the shortcut. Do you suppose setting its attributes to "Read Only" might be a solution?
My Weed Trek video archive: http://weedtrek.ca
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by Jim Dunn » 20 Mar 2021, 23:31

I think mikeyww's command does indeed set a registry key: https://superuser.com/questions/1408920/what-does-a-disablelastaccess-value-of-3-mean

So you could potentially read and store that key/value (or check for its presence/absence), change it if necessary, do what you need to, then set it back how it was.

But you're still potentially left needing to restart the system (twice?) - and, if so, that probably doesn't help much. :cry:

You can, of course, at least check its value on your testing machine to see if that's actually potentially the cause of your issue - you might even rule it out as a cause that way, who knows?

According to this: https://superuser.com/questions/251263/the-last-access-date-is-not-changed-even-after-reading-the-file-on-windows-7 that flag defaulted to disabled on Windows 7.
Last edited by Jim Dunn on 20 Mar 2021, 23:43, edited 1 time in total.
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 20 Mar 2021, 23:42

I'm going to try that disable command with a run comspec before the beginning of the loop, then re-enabling it after the loop, but only if it wasn't disabled initially (by checking that reg key) Then I'll wait until midnight and run the script again to see if it had any effect without a restart. Thanks Jim Dunn :D I'll report back tomorrow with any results.
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by mikeyww » 21 Mar 2021, 06:56

I hate "intruding" on anyone's computer to make arbitrary changes in the way their Windows deals with every shortcut from that point onwards.
Just my own view: it seems to me that the greater intrusion would be disabling a feature that the Windows user had been using. In reality, of course, I think that very few people would really use this feature or care about it. Cleanup programs tap into it, to figure out which files have not been accessed recently. In summary, I think of a program that would modify this as potentially mischievous.
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 21 Mar 2021, 15:09

mikeyww wrote:
21 Mar 2021, 06:56
Just my own view: it seems to me that the greater intrusion would be disabling a feature that the Windows user had been using. In reality, of course, I think that very few people would really use this feature or care about it. Cleanup programs tap into it, to figure out which files have not been accessed recently. In summary, I think of a program that would modify this as potentially mischievous.
:) I would tend to agree with that completely in the case of workarounds with reg keys etc... so it remains unknown if there's a way to check the datestamp without altering that datestamp while doing so... this means using FileSetTime for injecting "Last Accessed Date" has no purpose whatsoever?
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by mikeyww » 21 Mar 2021, 16:20

I tried the basic loop, worked just fine. What makes you think that it does not work? Have you used an AHK command to display the date before and after, and found differences in the cases when Continue does not occur?
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by Jim Dunn » 21 Mar 2021, 16:25

WeedTrek wrote:
21 Mar 2021, 15:09
this means using FileSetTime for injecting "Last Accessed Date" has no purpose whatsoever?
Presumably it becomes useful when/if the automatic updates every time a file is read are disabled?
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 21 Mar 2021, 17:25

mikeyww wrote:
21 Mar 2021, 16:20
I tried the basic loop, worked just fine. What makes you think that it does not work? Have you used an AHK command to display the date before and after, and found differences in the cases when Continue does not occur?
Yes sir, I've been able to confirm that. But then next morning when I run it again (or after technical day change at midnight) the new accessed stamps shows the current date and time. Leads me to presume accessing it to change the access date only temporarily works until the system is restarted? I have no idea, that's kind of why I'm here.
example.jpg
example.jpg (86.08 KiB) Viewed 1147 times
Here is what I mean... today I accessed "cathy songs - Shortcut" at 12:39pm, and "check downloads" at 1:01pm and also "Kamloops Court Search" at 1:01pm, all at around 3pm. I'm not sure why the rest say "12:43pm", that may have been when I ran the script. I haven't run Ccleaner or anything else that reads shortcuts.
Jim Dunn wrote:
WeedTrek wrote:
21 Mar 2021, 15:09
this means using FileSetTime for injecting "Last Accessed Date" has no purpose whatsoever?
Presumably it becomes useful when/if the automatic updates every time a file is read are disabled?
It "should" work but in this case does not work after a while, and a registry change demands a restart so that's a little out of bounds :)
My Weed Trek video archive: http://weedtrek.ca
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 21 Mar 2021, 17:46

Here's the entire script if anyone's interested. For some reason its not exiting completely, it leaves the icon in the systray. I think I might be the cause of this problem but I'm unable to figure out how. Here is the entire package. Sort of works, will not actually move anything of yours at all but shows MsgBox instead of moving anything. It exits except for the tray icon? weird, maybe that's part of this issue. There's Gui1, 2 and 3 I wonder if I should just use 1.
Desktop_Cleanup.zip
(17.23 KiB) Downloaded 28 times
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by mikeyww » 21 Mar 2021, 20:34

What does this do?

Code: Select all

if InitialShortcutsFound =
	InitialShortcutsFound = none
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 21 Mar 2021, 21:59

mikeyww wrote:
21 Mar 2021, 20:34
What does this do?

Code: Select all

if InitialShortcutsFound =
	InitialShortcutsFound = none
After that, if no shortcuts are found, it does this on line 117:

Code: Select all

}
if InitialShortcutsFound = none
{
	ShortcutTextAboveListbox = ; the word "Shortcuts:" is removed from above results listbox
	ShortcutInfo = Windows did not find any desktop shortcuts to clean up. ; This text is inserted into the variable which populates text on the results GUI
	GoBack = ; this var is made empty, usually would say "To change the shortcuts you want to move, click Back.
	GuiControl, Hide, List2 ; results listbox is hidden entirely, as the original XP does
}
I really should comment the code better, I usually do, sorry about that :) I'll go through it tonight
I could delete that part, and on that last chunk, use "if InitialShortcutsFound = " instead. That's for after it works, pruning out all the "low hanging fruit" and making it look more accurate to the original.
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts  Topic is solved

Post by mikeyww » 22 Mar 2021, 05:39

The script exited when I tested it. If yours does not exit, hover over the icon first, to ensure that you are not seeing a "ghost" or remnant of the icon. If the script did not exit, you can backtrack in the subroutine to find out which commands are executing.

In terms of the dates, you may be seeing effects from Windows's own access of the files. You could copy the files to a different directory and test with that. If you use any sort of external programs like indexers, cleanup, etc.-- and possibly some antivirus software-- you could be triggering accesses there, too.
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 22 Mar 2021, 13:46

mikeyww wrote:
22 Mar 2021, 05:39
The script exited when I tested it. If yours does not exit, hover over the icon first, to ensure that you are not seeing a "ghost" or remnant of the icon. If the script did not exit, you can backtrack in the subroutine to find out which commands are executing.

In terms of the dates, you may be seeing effects from Windows's own access of the files. You could copy the files to a different directory and test with that. If you use any sort of external programs like indexers, cleanup, etc.-- and possibly some antivirus software-- you could be triggering accesses there, too.
I have come to the very same conclusion :) thanks very much mikeyww I appreciate your help :D looks like I'll finish this particular XP counterfeit just for looks and not for function. How could the world do without this beautiful and invaluable tool though?? Chris Davis from Seattle was the one who killed the program in XP back in 2006, it was called out by Microsoft as "annoying, inappropriate, useless, irrelevant notifications"
His blog about it is kind of funny: https://chrdavis.github.io/I-Killed-The-Windows-Desktop-Cleanup-Wizard/
R.I.P.
Desktop Cleanup Wizard
2000 - 2006
My Weed Trek video archive: http://weedtrek.ca
User avatar
mikeyww
Posts: 26981
Joined: 09 Sep 2014, 18:38

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by mikeyww » 22 Mar 2021, 13:55

Thanks for the follow-up. Perhaps part of the point is that today's files are accessed so frequently and so broadly by so many different programs, that the number of great uses for knowing the last access date appears to have dwindled. This has been part of the evolution of Windows-- greater automation and power, but also much greater overhead that comes along with them.
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Preserving "Last Accessed" Datestamp In Shortcuts

Post by WeedTrek » 22 Mar 2021, 16:38

Yah I totally agree. Back in 2001 - 2005 there wasn't much in the way of cleaning software the general average user was looking for. The approach to cleaning out temp files was two-faceted... dealing with temp Windows files was rarely done and led to many slowdowns (and brought me a lot of work back then :) ) and dealing with temp internet files was generally done via the browser. Now there's a million "clean everything and the registry too" programs and I think a lot of regular polling and accessing is going on in the background of Windows, especially with all the potential avenues to gather data available to them with Cortana and Defender etc.
My Weed Trek video archive: http://weedtrek.ca
Post Reply

Return to “Ask for Help (v1)”