Proper sleep operation on systems with connected standby enabled

Standard API for sleep (`SetSuspendState`) seems to do nothing on
systems with connected standby.

Windows start menu calls `NtPowerInformation(ScreenOff)` on such systems instead.
This is implemented in `shutdownux!ShutdownViewModel::_InitiatePowerTransition` function.

Fixes #719
This commit is contained in:
ge0rdi
2022-12-20 15:50:28 +01:00
parent 23a1dc7e07
commit db0e768f81
+29 -1
View File
@@ -663,6 +663,33 @@ private:
#endif #endif
#define EWX_INSTALL_UPDATES 0x00100000 // undocumented switch to install updates on shutdown #define EWX_INSTALL_UPDATES 0x00100000 // undocumented switch to install updates on shutdown
NTSTATUS
NTAPI
NtPowerInformation(
_In_ POWER_INFORMATION_LEVEL InformationLevel,
_In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer,
_In_ ULONG InputBufferLength,
_Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
_In_ ULONG OutputBufferLength
);
static bool ConnectedStandby()
{
SYSTEM_POWER_CAPABILITIES powerCaps{};
GetPwrCapabilities(&powerCaps);
if (powerCaps.AoAc)
{
static auto pNtPowerInformation = static_cast<decltype(&NtPowerInformation)>((void*)GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtPowerInformation"));
if (pNtPowerInformation)
pNtPowerInformation(ScreenOff, NULL, 0, NULL, 0);
return true;
}
return false;
}
static bool ExecuteSysCommand( TMenuID menuCommand ) static bool ExecuteSysCommand( TMenuID menuCommand )
{ {
CComPtr<IShellDispatch2> pShellDisp; CComPtr<IShellDispatch2> pShellDisp;
@@ -885,7 +912,8 @@ static bool ExecuteSysCommand( TMenuID menuCommand )
WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,FALSE); WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,FALSE);
Sleep(250); Sleep(250);
} }
CreateThread(NULL,0,SleepThread,(void*)FALSE,0,NULL); if (!ConnectedStandby())
CreateThread(NULL,0,SleepThread,(void*)FALSE,0,NULL);
return true; return true;
case MENU_HIBERNATE: case MENU_HIBERNATE: