gawindx / WinNUT-Client

This is a NUT windows client for monitoring your ups hooked up to your favorite linux server.
GNU General Public License v3.0
386 stars 70 forks source link

Hibernate/Sleep Shutdown process following the full timer means Windows can't be restarted again (tries to repeat shutdown) #123

Open g-cranston opened 2 years ago

g-cranston commented 2 years ago

If Shutdown is set to occur via a timer delay, and this is allowed to run all the way to zero to activate Shutdown, where type of shutdown is either hibernate or sleep: then when the computer restarts to login screen, it immediately performs the same shut down again, causing a loop which is impossible to escape. (Have to reboot to safe mode).

I get the Windows 10 login screen for about 1-2 seconds, before it goes back into hibernation, so not enough time to get in and stop it. I assume the shutdown timer window is still trying to complete it's shutdown request, or is retrying it again - I think I managed to log in quickly once and saw the timer screen still there/doing its thing. This issue doesn't happen if 'Immediate stop action' is selected, or if you click the 'Immediate Shutdown' button on the shutdown timer window.

In Private Sub Shutdown_Timer_Tick, there is only one line after the Shutdown command:

        WinNUT.Shutdown_Action()
        Run_Timer.Enabled = False

I have expanded the commands after the Shutdown command, and it seems to work for me in every situation I try now. I am not sure if this is the best/appropriate coding to actually change, but works for me, and will reactivate on next power loss. I can log back in after restart, and WinNut is still running normally with no sign of the timer process that seems to be causing the problem.

    Private Sub Shutdown_Timer_Tick(sender As Object, e As EventArgs)
        Shutdown_PBar.Value = 100
        System.Threading.Thread.Sleep(1000)
        WinNUT.Shutdown_Action()
        Run_Timer.Enabled = False
        Me.Shutdown_Timer.Stop()   'GC
        Me.Shutdown_Timer.Enabled = False   'GC
        Me.Grace_Timer.Stop()   'GC
        Me.Grace_Timer.Enabled = False   'GC
        Me.Hide()   'GC
        Me.Close()   'GC
    End Sub