Skip to content

Commit 80f2e9e

Browse files
committed
Use .net framework calls for power mode change
- Not sure why we're making a Windows API call for power state change requests when the call already exists in the Windows.Forms class. Using that instead (works for me (tm)) - Adding some additional log messages as well
1 parent 77dc156 commit 80f2e9e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ Public Class WinNUT
8484
Private Event UpdateBatteryState(Reason As String)
8585
' UPS object operation
8686
Private Event RequestConnect()
87-
' Private Event RequestDisconnect()
88-
89-
'Handle sleep/hibernate mode from windows API
90-
Declare Function SetSuspendState Lib "PowrProf" (Hibernate As Integer, ForceCritical As Integer, DisableWakeEvent As Integer) As Integer
9187

9288
Private Sub WinNUT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
9389
' Make sure we have an app directory to write to.
@@ -285,6 +281,7 @@ Public Class WinNUT
285281
End Sub
286282

287283
Private Sub SystemEvents_PowerModeChanged(sender As Object, e As Microsoft.Win32.PowerModeChangedEventArgs)
284+
LogFile.LogTracing("PowerModeChangedEvent: " & e.ToString(), LogLvl.LOG_NOTICE, Me)
288285
Select Case e.Mode
289286
Case Microsoft.Win32.PowerModes.Resume
290287
LogFile.LogTracing("Restarting WinNUT after waking up from Windows", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
@@ -1100,13 +1097,15 @@ Public Class WinNUT
11001097
End Sub
11011098

11021099
Public Sub Shutdown_Action()
1103-
Select Case Arr_Reg_Key.Item("TypeOfStop")
1100+
Dim stopAction = Arr_Reg_Key.Item("TypeOfStop")
1101+
LogFile.LogTracing("Executing stop action " & stopAction, LogLvl.LOG_NOTICE, Me)
1102+
Select Case stopAction
11041103
Case 0
11051104
Process.Start("C:\WINDOWS\system32\Shutdown.exe", "-f -s -t 0")
11061105
Case 1
1107-
SetSuspendState(False, False, True) 'Suspend
1106+
Application.SetSuspendState(PowerState.Suspend, False, True)
11081107
Case 2
1109-
SetSuspendState(True, False, True) 'Hibernate
1108+
Application.SetSuspendState(PowerState.Hibernate, False, True)
11101109
End Select
11111110
End Sub
11121111

0 commit comments

Comments
 (0)