Turn on/off monitor(s) by command

MIRKOSOFT

Member
Hi!

I'm new here. I have installed Windows 10.1903 Pro x64.
I'm using many ways to realize tasks. Now I want to ask if is possible to turn on or off monitor (in my case 3 monitors) connected to computer by any command. Best in command line - it needs not extra options, I can plan it by my wish or so, only one option will be useful - specify selected monitor.

Thank you for help.
 

MIRKOSOFT

Member
I found solution over the web.
You can use attached in archive - run as admin. It forces monitor(s) off after start.
Note: I'm not author, only copied and tested, works.

Miro
 

Attachments

  • Turn off Screen.7z
    298 bytes · Views: 15

AdrianG001

Well-Known Member
Someone at Microsoft has created a batch file that turns off all monitors when launched. You can download the batch file from the link above or create one on your own with the following code:

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)

A PowerShell Script
Similar to the batch file above, here is a PowerShell script file that you can download and run for yourself.
Here is the source code if you are interested:

Code:
function Set-DisplayOff



{



$code = @"



using System;



using System.Runtime.InteropServices;



public class API



{



[DllImport("user32.dll")]



public static extern



int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);style='box-sizing: border-box'>

}



"@



$t = Add-Type -TypeDefinition $code -PassThru



$t::SendMessage(0xffff, 0x0112, 0xf170, 2)



}



Set-DisplayOff

Regards,
Adrian
 
Top