karpach / remote-shutdown-pc

Remote Shutdown Manager is a windows application, which gives an ability to shutdown, suspend, hibernate PC or turn screen off using HTTP GET request.
342 stars 49 forks source link

REQ: Turn screen off remotely #2

Closed LarsNorgaard closed 5 years ago

LarsNorgaard commented 6 years ago

Would be nice, if there was an option to turn the screen off remotely too.

karpach commented 6 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();
    }
LarsNorgaard commented 5 years ago

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.

karpach commented 5 years ago

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.

karpach commented 5 years ago

I added turn screen off functionality.

Philou06 commented 3 years ago

Hi, what is the syntax to use for the "Turn off screen" command please? http://remote-host-name:5001/turnoffscreen? ../turn-off-screen?

karpach commented 2 years ago

The syntax is http://remote-host-name:5001/secret/turnscreenoff/