[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.
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
Re: Determine whether Hibernate is enabled or not
Quote:
Originally Posted by
4x2y
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
Re: Determine whether Hibernate is enabled or not
Quote:
Originally Posted by
soulblazer
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.
Re: Determine whether Hibernate is enabled or not
Quote:
Originally Posted by
4x2y
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