CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Can't get time off of the hiberfil.sys

    I need to get time when hiberfil.sys was last modified to be able to distinguish if PC was woken up from hibernation or sleep mode, but my every attempt to open that file results in error 32: Sharing violation. I know that it's possible to get it's time modified stamp, since both Explorer and my other file browser return it OK. Does anyone know how to do it?

    PS. I tried GetFileAttributesEx() and CreateFile(name, FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL) and both failed.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Can't get time off of the hiberfil.sys

    The Explorer probably uses FindFirstFile(). Try it...

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can't get time off of the hiberfil.sys

    I spent some time with CreateFile yesterday but didn't solve it.

    I did try this in C# using the FileInfo class and it worked fine.

    I loaded up the system.dll in Reflector to see if I can determine the underlying FileInfo implementation, but it's a bit complicated for the cursory look I gave. With more time, one should be able to track down the api's and necessary permissions by looking at the .net implementation.

    P.S. I didn't have hyperfil.sys so I used pagefile.sys.

    In C#, it's one line of code.
    Attached Images Attached Images  
    Last edited by Arjay; August 24th, 2009 at 09:37 PM.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Can't get time off of the hiberfil.sys

    Try FindFirstFile.

    gg

  5. #5
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Can't get time off of the hiberfil.sys

    Yeah, I tried the first poster's suggestion and strangely enough FindFirstFile was able to give the time stamps, etc. None of the other approaches worked. Thank you guys!

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can't get time off of the hiberfil.sys

    Quote Originally Posted by ahmd View Post
    Yeah, I tried the first poster's suggestion and strangely enough FindFirstFile was able to give the time stamps, etc. None of the other approaches worked. Thank you guys!
    That's not entirely true - the C# approach works.

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Can't get time off of the hiberfil.sys

    How come no one remembers stat()? I must be too old.

    Code:
      struct _stat buffer;
      char timebuf[26];
    
      int rc=_wstat(L"c:\\hiberfil.sys",&buffer);
      ctime_s(timebuf, 26, &buffer.st_mtime);

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Can't get time off of the hiberfil.sys

    Quote Originally Posted by hoxsiew View Post
    How come no one remembers stat()? I must be too old.

    Code:
      struct _stat buffer;
      char timebuf[26];
    
      int rc=_wstat(L"c:\\hiberfil.sys",&buffer);
      ctime_s(timebuf, 26, &buffer.st_mtime);
    The stat() should work as well, but that is just a runtime library wrapper that uses FindFirstFile()/ FindNextFile() internally.

    Quote Originally Posted by Arjay
    That's not entirely true - the C# approach works.
    It probably does the same on the inside of one of the NET libraries.

    From personal experience FindFirstFile()/FindNextFile() are the only APIs that can retrieve information for files that cannot be opened by any other means -- they are like "APIs of last resort" in a sense. And I don't think that there's any lower level API that can be accessed from a user (non-driver) environment, is there?
    Attached Files Attached Files
    Last edited by dc_2000; March 14th, 2015 at 10:39 PM.

  9. #9
    Join Date
    Dec 2008
    Posts
    114

    Re: Can't get time off of the hiberfil.sys

    Quote Originally Posted by ahmd View Post
    I need to get time when hiberfil.sys was last modified to be able to distinguish if PC was woken up from hibernation or sleep mode
    It won't help : hiberfil.sys is not updated when Windows hibernates...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured