WinNUT-Client icon indicating copy to clipboard operation
WinNUT-Client copied to clipboard

Hibernate Type Of Stop doesn't hibernate computer

Open robotics13 opened this issue 3 years ago • 19 comments

When I configure WinNUT to Hibernate my computer the Shutdown GUI will display when the NUT Server sends the FSD signal. The Shutdown GUI will perform the countdown and then hang. When configured to Shutdown instead of hibernate, the shutdown process executes properly.

Steps to reproduce:

  1. Configure WinNUT Shutdown Options as follows
  • Type of Stop = Hibernate
  • Delay to SHutdown (sec) = 15
  • Shutdown on Nut's FSD Signal = Checked
  1. Disconnect UPS from AC power, wait for NUT Server to send FDS
  2. Shutdown GUI will appear, wait for counter to reach zero
  3. Shutdown GUI will hang and computer will stay powered on

I suspect this has something to do with the calls to SetSystemPowerState in the Select Cast statement at line 979 in WinNUT.vb. It looks a bit odd passing a Boolean value when the function is declared as expecting an integer. https://www.tek-tips.com/viewthread.cfm?qid=1086465 talks about similar code only passing integers 1 and 0 instead of Booleans. It has been years since I messed with VB.Net so passing a Boolean could be valid, it just looks off.

My computer is running Windows 10 21H1, NUT Server is the built in Synology NUT server, running latest version of WinNUT

robotics13 avatar Jul 08 '21 02:07 robotics13

I took a second look at this and the problem was my computer does not have the Hibernate option enabled.

Not sure if the a try catch around the Hibernate command would be helpful or if an update to the documentation/UI would be better.

robotics13 avatar Jul 09 '21 13:07 robotics13

Same. Shutdown works and hibernation and sleep doesn't. Windows 10, WinNUT 2.0.7722.30975

Ha4ipuri avatar Oct 22 '21 14:10 Ha4ipuri

I can confirm this. I was trying to use the "shutdown on FSD" setting with a Synology NAS. It only works for "Shutdown" and NOT for "hibernate" or "sleep". If you have a delay set for hibernate or sleep, the program will crash after the delay.

johnehler avatar Oct 26 '21 00:10 johnehler

I have come all the way to the same final hurdle: Shutdown works great, Hibernate/Sleep just don't trigger an action, whether at the end of the timer, clicking the immediate shutdown button on the timer, or without timer. I have hibernate switched and working otherwise. Have tried this on a PC and laptop, for both v2.0.7722.30975 (stable) and v2.1.7740.35837 (pre-release). Windows 10 21H2 / 21H1, built-in Synology UPS server. If power is restored, timer window disappears and it carries on as normal.

I don't know if it has any bearing at all, but on my current windows machines, the command: shutdown.exe /h /t 5 does nothing (shows the syntax guide) when I would expect it to delay hibernation for 5 secs from documentation.

Whereas: shutdown.exe /h hibernates immediately as it should do.

g-cranston avatar Dec 01 '21 14:12 g-cranston

#116

I think a possible answer to this may have been suggested in a new post.

g-cranston avatar Jan 25 '22 14:01 g-cranston

This worked for me as hoped, once SetSystemPowerState was swapped for SetSuspendState, on Windows 10. Not sure quality of my coding, but this worked for me:

Public Sub Shutdown_Action()
     Select Case WinNUT_Params.Arr_Reg_Key.Item("TypeOfStop")
        Case 0
             Process.Start("C:\WINDOWS\system32\Shutdown.exe", "-f -s -t 0")
       Case 1
             SetSystemPowerState(True, 0)
       Case 2
             SetSystemPowerState(False, 0)
     End Select
End Sub

Changed to:

Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer

    Public Sub Shutdown_Action()
        Select Case WinNUT_Params.Arr_Reg_Key.Item("TypeOfStop")
            Case 0
                Process.Start("C:\WINDOWS\system32\Shutdown.exe", "-f -s -t 0")
            Case 1
                SetSuspendState(False, False, True)  'suspended
            Case 2
                SetSuspendState(True, False, True)   'hibernated
        End Select
    End Sub   

g-cranston avatar Feb 01 '22 23:02 g-cranston

Hi g-cranson, Is there a fork or installable download that contains this fix?

p7654 avatar Feb 15 '22 16:02 p7654

https://github.com/g-cranston/WinNUT-Client

Have made the changes in a fork in case it is of use (plus another fix for a different issue that works for me). Apologies if I haven't done this in the appropriate manner (first time doing this on github).

g-cranston avatar Feb 16 '22 00:02 g-cranston

Hey everyone, again apologies for letting these bugs sit for so long without an update. I've been working for a very long time on a big change, but I'm realizing how important it is that we get these high profile bugs fixed.

I think @gawindx gave me write access to this repo. @g-cranston do you want to make a pull request here with your changes, then I'll pull it in along with a few other waiting PRs and push out an update?

gbakeman avatar Feb 16 '22 01:02 gbakeman

@gbakeman Hopefully I've done the pull request right - seem to be two modifications in one rather than separated.

Thank you for all you and @gawindx have done for this project, a huge and really worthwhile piece of work. Has really solved my situation where APC's solution didn't!

g-cranston avatar Feb 16 '22 01:02 g-cranston

I'm glad I could be a part of this, and thank you for the PRs. I'm away from the dev computer right now but I'll make it a priority to get your work by next week, hopefully before.

gbakeman avatar Feb 16 '22 04:02 gbakeman

Excellent work by the way, thank you! I just found out that I made a mistake sleeping on @gawindx 's invitation. Apparently they expire in 7 days, and that was a long time ago when they sent it. I'll see if I can contact him (maybe you can too if you want to do more?)

gbakeman avatar Feb 17 '22 04:02 gbakeman

For everyone following this: Thanks to the work of @g-cranston , we have a debug build available. Please download it from here and report back results.

gbakeman avatar Jul 25 '22 22:07 gbakeman

I have tried to been using 2.0.7722.30975 and I also can only get it shutdown and not sleep I updated to 2.1.7740.35837, but that didn't even give me the dialog box when it went below the battery capacity set in settings. I tried to run 2.1.8241.26516 as a stand alone, (as it was just in a zip file, so i extracted the folder and ran the WinNUT-client.exe and again it does the exact same thing at 2.0.7722.30975, where is says it has the delay timer, and then nothing happens.

I can only assume i am to stupid to get this working. Is there an install file that has a proper fix, as when i see the fixes in the source code, it means nothing to me where to apply them.

I am running NUT Server on a raspberry Pi, and Win Client on windows 10, fully up to date.

It took me the best part of 2 weeks to try and get NUT to run on a pi, so i am not good with code, and I am sure there are other out there like me that need our hands held.

Please can someone help.

Thanks

DravenSA avatar Sep 28 '22 19:09 DravenSA

Hi,

Development of WinNUT has moved to the repository at nutdotnet/WinNUT-Client. This issue can be found duplicated here. Please try the latest pre-release and see if that works. I'd prefer if all future issues and discussion happen over in the new repository.

Thank you for taking the time to provide your feedback, I hope you'll submit some more!

gbakeman avatar Sep 28 '22 19:09 gbakeman

Development of WinNUT has moved to the repository at nutdotnet/WinNUT-Client.

This really should be indicated in the README.
Hadn't I had this hibernation issue I would never had known since this repo is still the first (and only, it seems) coming up when looking for winnut on a search engine.

psychopatt avatar Jun 08 '23 08:06 psychopatt

This really should be indicated in the README.

I created a PR to do so, but I think it would be a good idea to also forbid new issues and PRs if possible.

psychopatt avatar Jun 08 '23 08:06 psychopatt

I wish I had the power to do so! @gawindx granted me access years ago but I didn't accept the invite in time. I've lost all contact with them since and GitHub support hasn't been able to help, so this has sort of become a zombie repository. I might try working on some SEO to boost the new repository up in search rankings though.

gbakeman avatar Jun 08 '23 09:06 gbakeman

Ok, that's too bad. Hopefully the PR will catch the eye of anyone in the same situation and they'll find the new repo more easily. Anyway, thanks for your work!

psychopatt avatar Jun 08 '23 10:06 psychopatt