'Win API to disable Windows Dynamic Lock (aka Windows Goodbye)

I am trying to temporarily disable the Windows Dynamic Lock while running long operations on my computer when I don't want the computer to sleep, lock or turn turn off the screen. I have found a way to do this by toggling the following Windows registry key between 1 and 0 but I'd prefer to use a Windows API to make the update in the event there are other dependencies in which I am unaware of.

HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\EnableGoodbye

Anyone know which Windows API allows reads and updates to this setting?

I have had a few people mention SetThreadExecutionState, so I am adding a link to a repo to show that I am already using that.



Solution 1:[1]

It is possible that there are no APIs for that at all.

Normally application call SetThreadExecutionState to bypass poweroff, handle SC_SCREENSACE / SC_MONITORPOWER to keep display on.

But locking on inactivity is a security feature, so I don't think applications should easily manipulate it. I believe applications should suggest users to disable it manually instead, so that users would explicitly disable it. I therefore think there's no API.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Guteniev