You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
815 B
Python
30 lines
815 B
Python
1 year ago
|
# -*- coding: utf-8 -*-
|
||
|
# 使用ctypes模块进行操作
|
||
|
from ctypes import *
|
||
|
import time
|
||
|
#user32 = windll.LoadLibrary('user32.dll')
|
||
|
#user32.LockWorkStation()
|
||
|
HWND_BROADCAST = 0xffff
|
||
|
WM_SYSCOMMAND = 0x0112
|
||
|
SC_MONITORPOWER = 0xF170
|
||
|
MonitorPowerOff = 2
|
||
|
SW_SHOW = 5
|
||
|
|
||
|
def main():
|
||
|
windll.user32.PostMessageW(HWND_BROADCAST, WM_SYSCOMMAND,
|
||
|
SC_MONITORPOWER, MonitorPowerOff)
|
||
|
shell32 = windll.LoadLibrary("shell32.dll")
|
||
|
shell32.ShellExecuteW(None,'open', 'rundll32.exe',
|
||
|
'USER32,LockWorkStation','',SW_SHOW)
|
||
|
def printSleep():
|
||
|
tmp = 10
|
||
|
load = 60
|
||
|
for x in range(tmp):
|
||
|
print(load*(tmp-x),"秒后锁屏")
|
||
|
time.sleep(load)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print( "Win32 Application in python" )
|
||
|
printSleep()
|
||
|
main()
|