How to turn off screen with PowerShell?

9,519

Solution 1

From this TechNet scripting page:

powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

Solution 2

(Running this has the side effect of also locking the workstation in Windows 10. You will need to know the password in order to log back in)

Running in Powershell:

(Add-Type '[DllImport("user32.dll")]public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

Would be the correct answer in order to turn off the display. Yes, it also turns off the display on a laptop using Powershell (and some .NET C# code)

Share:
9,519

Related videos on Youtube

A.Ishah
Author by

A.Ishah

Coding for fun.

Updated on September 18, 2022

Comments

  • A.Ishah
    A.Ishah over 1 year

    I need to be able to turn off my screen instantly manually.

    I tried powercfg /change monitor-timeout-ac 0, but looks like setting the value to 0 turns it to never. Values like 0.1 also change it to never.

    Is there any way I can set this value to 0 minutes, or is there another command that i can use to turn off my screen manually?