关闭显示器

用PYTHON关闭显示器很方便,网上找的代码,保存为PY,直接运行即可。
 1 #python 3.4 win7
 2 from ctypes import *
 3 from ctypes.wintypes import *
 4 
 5 HWND_BROADCAST = 0xffff
 6 WM_SYSCOMMAND = 0x0112
 7 SC_MONITORPOWER = 0xF170
 8 MonitorPowerOff = 2
 9 SW_SHOW = 5
10 
11 def main():
12     windll.user32.PostMessageW(HWND_BROADCAST, WM_SYSCOMMAND,
13                                SC_MONITORPOWER, MonitorPowerOff)
14     
15     shell32 = windll.LoadLibrary("shell32.dll");
16     shell32.ShellExecuteW(None,'open', 'rundll32.exe',
17                           'USER32,LockWorkStation','',SW_SHOW)
18 
19 if __name__ == "__main__":
20     print( "Win32 Application in python" )
21     main()

 

posted @ 2016-10-25 13:14  stephen2016  阅读(762)  评论(0编辑  收藏  举报