Tech Support > Microsoft Windows > Development Resources > CreateFile updates last-access time on Win Me
CreateFile updates last-access time on Win Me
Posted by Norman Bullen on December 19th, 2004


Steven Kobes wrote:
For what it's worth, the documentation says that
FILE_FLAG_BACKUP_SEMANTICS is not supported on 9x and Me systems. That
doesn't explain why this seems to work (as you say) on 95 and not on Me.

Norm

--
--
To reply, change domain to an adult feline.


Posted by Steven Kobes on December 19th, 2004


Norman Bullen wrote:
I also tried it without FILE_FLAG_BACKUP_SEMANTICS, and the results
were identical. I am pretty sure it's a stupid bug in Win Me. This
is freaky, try it:

1. create a folder with two files, A and B, set view to "Details"
2. right-click column header -> "More..." -> check "Accessed" -> OK
3. set clock forward a day
4. View -> Refresh, note old last-access date
5. SINGLE-click* B, then A (don't open, just highlight)
6. View -> Refresh, note NEW last-access date on both files!

* This assumes you've selected the "double-click to open" mode in
Tools -> Folder Options. In "single-click to open" mode, all you have
to do is HOVER the mouse over B, then A!

Posted by Steven Kobes on December 30th, 2004


From MSDN:

"An application that cannot understand the contents of the files it is
accessing should save the last access date and restore it after
closing the file. [...] Applications can preserve the last access
date by using the GetFileTime and SetFileTime functions."

Since GetFileTime requires a handle from CreateFile, this implies that
CreateFile can be called without changing the last-access date. And
on two systems I've tested -- Windows 95 and XP -- this works as
expected.

But on a Windows Me system, calling CreateFile always seems to set the
last-access date!

My code:

HANDLE hfile = CreateFile("hello.txt", GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);

if (hfile != INVALID_HANDLE_VALUE) {
getchar();
CloseHandle(hfile);
}

I run it as follows:

1. Set system clock back a week
2. Create hello.txt with COPY CON
3. Set system clock forward a week
4. Run program
5. While paused in getchar(), open second DOS prompt
6. View last-access date with DIR /v

I've tried various combinations of CreateFile flags and access rights,
but DIR always shows an updated last-access date. It seems like a bug
(one that makes GetFileTime useless for last-access dates on Win Me).
Has anyone ever gotten this to work?

TIA,
Steve


Similar Posts