I found code in various places which allows my c# program to turn the PCs monitors(2) on and off and they work fine (example of the one I am using from MS learning site below). My object in using the code is to programatically wake up my PC screen in response to an external event (for which I have a working handler – but which I removed from the test code).
In my control panel (Windows 10) in the “Power & Sleep” section I have Sleep setting as “Never” and to turn off the monitors after 15 mins of inactivity – which it does.
Hardware is an Intel processsor on an ASUS P8Z77-V-LX Motherboard with 16GB memory and 500GB HDD as system disk.
TIA – Alan T
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MONITORPOWER = 0xF170;
IntPtr HWND_BROADCAST = new IntPtr(0xffff);
// Shut down
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
// Open the
//SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
}
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, uint wParam, int lParam);
}
}`
If I simply use the c# test code below it switches my (2) monitor power off and on as advertised but my desktop does not come up – so it’s like the monitors are on but the PC is not. When I press any key on the keyboard it all comes back in just a few seconds. Also, when the PC monitors are blanked I can still ping the PC and access it remotely via VNC – so I know it’s not shutting down or hibernating.
Clearly there is some difference between the power control being used by control panel and the power control which this c# code is toggling – but how can I programatically access the right one to rewaken the desktop as well as the monitors?