在Windows中关闭显示器

可以使用SendMessage()PostMessage()消息API向系统发送关闭监视器的要求:

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MONITORPOWER = &HF170&
Private Const MONITOR_OFF = 2

Private Sub Form_Load()
     SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal MONITOR_OFF
     End
End Sub

命令行:

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

参考资料:

https://www.zhihu.com/question/46324376

it
除非特别注明,本页内容采用以下授权方式: Creative Commons Attribution-ShareAlike 3.0 License