Closed LarsNorgaard closed 5 years ago
Looks like there is no reliable way to do it. I just tried the following sample on my Windows 10. It turns screen off, but then it comes back on after a few seconds:
const int WM_SYSCOMMAND = 0x112;
const int SC_MONITORPOWER = 0xF170;
[DllImport("user32.dll")]
static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam);
public static void Main(string[] args)
{
bool turnOff = true; //set true if you want to turn off, false if on
PostMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, (turnOff ? 2 : -1));
Console.ReadKey();
}
Sorry for asking here again, but I found this powershell script that works with Windows 10: https://gist.github.com/oledid/fb02951b6b1848d1418d#file-turn-off-screen-ps1
I see it's able to run without admin rights, but don't know if powershell scripts/commands can be included in your program.
The above PowerShell script looks very similar to my example above. I just tried it and it worked on my work PC. It is possible that something wakes up my home PC. I'll investigate this further when I am at home. It should be easy to integrate PowerShell way into my code.
I added turn screen off functionality.
Hi, what is the syntax to use for the "Turn off screen" command please? http://remote-host-name:5001/turnoffscreen? ../turn-off-screen?
The syntax is http://remote-host-name:5001/secret/turnscreenoff/
Would be nice, if there was an option to turn the screen off remotely too.