Hello,
When running a Windows service, there are certain limitations and differences in the way the system behaves compared to running a console application.
One possibility is that the behavior is different because the service is running in a non-interactive session. Even if you have marked the service as interactive, starting from Windows Vista, interactive services are no longer supported. This means that the service runs in a separate session and does not have access to the desktop and user-specific features, including the display.
To work around this limitation, you can try the following approaches:
Use the Service Control Manager (SCM) to detect user logon/logoff events and run a separate user-mode process that calls SetThreadExecutionState when a user is logged on.
Instead of using a Windows service, you can create a separate user-mode application that runs in the user’s session and uses SetThreadExecutionState to control the system’s sleep and display behavior.
Consider using other methods or APIs that may be available for achieving the desired behavior in the context of a Windows service.
Best Regards,
Hania Lian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.