0

When I'm using

time_t t = last_write_time("C:\\System Volume Information");

I get the following exception:

boost::filesystem::last_write_time: Access denied: "C:\System Volume Information"

Nevertheless, Windows Explorer is able to get access to that information. It looks like Boost requires extra access to the folder, and that's the reason the code doesn't work.

Is it possible to make a workaround somehow?

Edit. Here's a citation from libs\filesystem\src\operations.cpp:1312:

handle_wrapper hw(
  create_file_handle(p.c_str(), 0,
    FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
    OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0));

I don't see what's wrong with it yet.

polkovnikov.ph
  • 6,256
  • 6
  • 44
  • 79
  • I think the obvious answer is going to be: not with `boost::filesystem::last_write_time`?I think the obvious answer is going to be: not with `boost::filesystem::last_write_time`. There migth be a Win32 approach, perhaps with sufficient privileges. And then there might be the "canon-shooting-the-fly" approach with Volume Shadow Copy... – sehe Feb 16 '15 at 13:22
  • @sehe In case it's not possible with Boost at all, it's a bug that should be reported. – polkovnikov.ph Feb 16 '15 at 13:26
  • Why? It's the discretion of the OS to restrict access to certain information. It's the task of the developer to handle errors :/ – sehe Feb 16 '15 at 13:36
  • @sehe This information is available. – polkovnikov.ph Feb 16 '15 at 13:38
  • 1
    It's not about availability. Your boot sector and kernel memory are _available_. It's about access though – sehe Feb 16 '15 at 13:39
  • @sehe I'm using administrator account, and the data are available in Windows Explorer without any elevation. What you're saying could make sense if Explorer had some access rights other programs don't have, but as far as I know that would raise too much security issues for MS to ever do it this way. – polkovnikov.ph Feb 16 '15 at 13:45

1 Answers1

4

That folder is off limits even to users with an Admin account, it contains restore points. Not that you couldn't change the ACL with such an account but that is of course not the correct solution. Trying to open a handle on the directory is too heavy-handed, use FindFirstFile() instead. Like this:

WIN32_FIND_DATA info;
auto hdl = FindFirstFile(L"C:\\System Volume Information", &info);
if (hdl == INVALID_HANDLE_VALUE) throw win32_error(GetLastError());
SYSTEMTIME time;
FileTimeToSystemTime(&info.ftLastWriteTime, &time);
// etc..
//...
FindClose(hdl);
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • This is the best solution, but note that if you *did* need to open a handle you wouldn't need to change the ACL to do it. If you enable backup and restore privilege, CreateFile will ignore the ACL. – Harry Johnston Feb 17 '15 at 00:20