Skip to content

Commit 4ab867f

Browse files
committed
PowerModeChanged handling
Apparently, Windows is not very consistent with reporting PowerModeChanged events so we need to account for that. Suspend code now runs in the Shutdown action to keep WinNUT in a more consistent state between power mode changes.
1 parent e52fa65 commit 4ab867f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,13 @@ Public Class WinNUT
281281
End Sub
282282

283283
Private Sub SystemEvents_PowerModeChanged(sender As Object, e As Microsoft.Win32.PowerModeChangedEventArgs)
284-
LogFile.LogTracing("PowerModeChangedEvent: " & e.ToString(), LogLvl.LOG_NOTICE, Me)
284+
LogFile.LogTracing("PowerModeChangedEvent: " & e.Mode, LogLvl.LOG_NOTICE, Me)
285285
Select Case e.Mode
286286
Case Microsoft.Win32.PowerModes.Resume
287287
LogFile.LogTracing("Restarting WinNUT after waking up from Windows", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
288288
If Arr_Reg_Key.Item("AutoReconnect") = True Then
289289
UPS_Connect()
290290
End If
291-
Case Microsoft.Win32.PowerModes.Suspend
292-
LogFile.LogTracing("Windows standby, WinNUT will disconnect", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP))
293-
UPSDisconnect()
294291
End Select
295292
End Sub
296293

@@ -1098,7 +1095,9 @@ Public Class WinNUT
10981095

10991096
Public Sub Shutdown_Action()
11001097
Dim stopAction = Arr_Reg_Key.Item("TypeOfStop")
1101-
LogFile.LogTracing("Executing stop action " & stopAction, LogLvl.LOG_NOTICE, Me)
1098+
LogFile.LogTracing("Windows going down, WinNUT will disconnect.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP))
1099+
UPSDisconnect()
1100+
11021101
Select Case stopAction
11031102
Case 0
11041103
Process.Start("C:\WINDOWS\system32\Shutdown.exe", "-f -s -t 0")

0 commit comments

Comments
 (0)