Disabling display with Windows Service

I wrote a Windows service that should turn off the display when certain conditions occur. The code I'm using is:

private const int MONITOR_OFF = 2;
SendMessage(GetDesktopWindow().ToInt32(), 
   WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);

The same code works from a Windows application, but nothing happens when a Windows service is executed. There are also no exceptions, and Marshal.GetLastWin32Error()also returns 0.

Any ideas on what I might lose?

+3
source share
3 answers

, GetDesktopWindow() - , ; Int32 SendMessage(). , , , .

+5

, , .

+2

( .) , . , , , . /. , , .

0

Source: https://habr.com/ru/post/1723028/


All Articles