Windows 10 .NET user32.dll monitor state OFF acting as standby. Fix?

  • Thread starter Thread starter AstromanRB
  • Start date Start date
A

AstromanRB

When switching the monitor state to OFF using sendmessage (user32.dll, .net, C#, windows 10 pro), the monitor goes black, which is as intended. Any input (remote input in this case) or activity will set the monitor back to the ON state.

I feel this is what the "STANDBY" state is supposed to do, while the OFF state is supposed to stay off until I activate the monitor with another sendmessage, or restart the system. As well, standby seems to do nothing? Is this intended?

I would like a solution to the problem. I would like to make "off" off and "standby" standby.
I have a screen on a laptop that must remain open for diagnostic reasons, but only visible at specific times, unless the system is viewed remotely, in which case all diagnostics should become visible only to the remote viewer, and not to onlookers of the laptop screen.
I do not want people to touch the laptop for sanitation and security reasons. I need the system to run. I need the monitor off at specific times. An external monitor is not viable.

I'm not sure what I need to change, Registry? Code? Drivers? Group policy?

I know there are other "solutions" to the issue. Use an external monitor with a smart outlet, replace the LID driver with volume manager, switch the primary screen to the laptop with the lid closed, connect to an external monitor. These deviations will not work.

Once again, let me be very clear. I need to programmatically turn off, and programmatically turn on the monitor of the laptop.
Programmatically turning off the monitor has been achieved. Programmatically turning ON the monitor has failed, as the monitor turns on automatically by activity and remote input.
Essentially, the monitor must stay off until specified to do otherwise through code.
Changing the power options of devices to disallow them to wake the PC is meaningless and irrelevant.

I believe the monitor states are not valid for windows 10, possibly defined by a pervious version of windows. Why does standby do nothing? Why does off act as standby?
I'm trying to be very clear because I've inquired about this issue in several other places and got a great deal of misunderstanding.

No, this is not a "power and sleep" option. No, this is not a hibernate state. No, the laptop is not sleeping.
As far as I've checked, unless there's some manipulation of the task scheduler that I'm unaware of, this doesn't seem to be a control panel setting.

There are several nested questions in this post, but the primary question is: How can I disable the monitor from switching back to the "ON" state through input/activity, and only allow the monitor to return to the "ON" state once a user32.dll message to do so has been received, or possibly system restart?

Any help with this matter is highly appreciated. Thank you.


I have tried the following code:



  1. public enum MonitorState
  2. {
  3. ON = -1,OFF = 2,STANDBY = 1
  4. }


CODE 1:

  1. [DllImport("user32.dll")]
  2. static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  3. public static void SetMonitorState(MonitorState state)
  4. {
  5. SendMessage(new Form().Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)state);
  6. }


CODE 2:

  1. [DllImport("user32.dll")]
  2. static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam);
  3. public static void SetMonitorState(MonitorState state)
  4. {
  5. PostMessage(-1, (int)WM_SYSCOMMAND, SC_MONITORPOWER, (int)state);
  6. }

Continue reading...
 
Back
Top