Results 1 to 5 of 5

Thread: [RESOLVED] Determine whether Hibernate is enabled or not

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    10

    Resolved [RESOLVED] Determine whether Hibernate is enabled or not

    Hi, I have a simple application. During closing a form will show up and ask what to do: Whether close the application and shutdown (which drops a menu of "shutdown", "restart", "hibernate", "log off", "lock", "standy"), close temporarily (which closes both confirmation and main forms, but it doesn't shutdown) and cancel (which only closes the custom messagebox and cancels the FormClosing event)

    That works as expected.

    I have a little problem, though. Some users disable the Hibernate function to save some space (either by editing the registry or by using a third party software like TuneUp Utilities). I disabled my own Hibernate function to see what would happen if I tried to hibernate it with my application and... bam! Blue Screen of Death! (It also happens if I try to hibernate it the "Windows way" or if the laptop tries to hibernate due to low battery, so it's not anything my program is doing wrong) I've been told that Hibernate is determined by "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\HibernationPreviouslyEnabled", but I can't find that entry on my registry.

    That being explained, I need a way to determine if Hibernate is enabled so I can tell the user they can't select the "Hibernate" menu item due to the function being disabled and avoid the BSOD's or any other bugs.
    Last edited by soulblazer; Jan 2nd, 2015 at 06:10 PM.

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Determine whether Hibernate is enabled or not

    Dirty code
    Code:
    If File.Exists("hiberfil.sys") Then
        ' hibernate enabled
    Else
        ' hibernate disabled
    End If
    hiberfile.sys always on boot drive and cannot move elsewhere http://answers.microsoft.com/en-us/w...1-801a73d45ea8
    Last edited by 4x2y; Jan 2nd, 2015 at 10:06 PM.



  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    10

    Re: Determine whether Hibernate is enabled or not

    Quote Originally Posted by 4x2y View Post
    Dirty code
    Code:
    If File.Exists("hiberfil.sys") Then
        ' hibernate enabled
    Else
        ' hibernate disabled
    End If
    hiberfile.sys always on boot drive and cannot move elsewhere http://answers.microsoft.com/en-us/w...1-801a73d45ea8
    Since the file is always there, matter how much the code it's tested, it would always return true because the file cannot be moved (unless there's a weird virus going on there).

    What I meant was to not get rid of the file, it was to check if the value from the registry ("HibernateEnabled") that determines whether the function (not the file) was enabled to be used or not.
    Finally, I found out how to do it (though, I don't remember where exactly)

    Code:
     Public Function IsHibernationEnabled() As Boolean
            Return CBool(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power", "HibernateEnabled", 1))
        End Function
    It returns true if "HibernateEnabled" in the registry is 1, or false if it's 0 (It doesn't change anything, it just checks the value). The little problem now is I have yet to find out if this already existed on older versions of Windows. Anyway, I still appreciate that you took your time to answer and help.

    http://msdn.microsoft.com/en-us/libr...ded.60%29.aspx
    Last edited by soulblazer; Jan 5th, 2015 at 10:32 PM.

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Determine whether Hibernate is enabled or not

    Quote Originally Posted by soulblazer View Post
    Since the file is always there, matter how much the code it's tested, it would always return true because the file cannot be moved (unless there's a weird virus going on there).
    No, it is not always there because Windows delete "hiberfil.sys" when hibernate disabled to free disk space.

    Anyway getting hibernate status from the registry is better.



  5. #5
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Determine whether Hibernate is enabled or not

    Quote Originally Posted by 4x2y View Post
    No, it is not always there because Windows delete "hiberfil.sys" when hibernate disabled to free disk space.

    Anyway getting hibernate status from the registry is better.
    I would agree get it from the registry ... search google for the key, and look into reading the registry to read it from code!

    Kris

Tags for this Thread

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