1

The PowerShell command below turns off the screen when run from a batch file (or command prompt). I would prefer to run this as a PowerShell script.

Turn Off Screen - TechNet Script Center

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)

I looked at Add-Type - Microsoft Docs, but I could not get the parameters correct.

What is the equivalent PowerShell script for this?

1 Answer 1

3
Add-Type -MemberDefinition @"
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
"@  -Name "Win32SendMessage" -Namespace "Win32Functions"

[Win32Functions.Win32SendMessage]::SendMessage(-1,0x0112,0xF170,2)
Sign up to request clarification or add additional context in comments.

1 Comment

[Win32Functions.Win32SendMessage]::SendMessage(-1,0x0112,0xF170,-1) to turn monitor on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.