I ask you for help on something. What I want to do. If there is no keyboard or mouse movement for 10 minutes, I want the computers in our institution to mass their screens.
Actually, the following script you wrote works for me. This script works when I run it directly on a device. But when I add it in the monitor part. That is, to constantly check it every 5 minutes. This script does not work. I do not understand where I am making mistakes. Could you help. The script is below.
threshold_time =1 # should be less than 60 import subprocess from ctypes import * class LASTINPUTINFO(Structure): _fields_ = [ ('cbSize', c_uint), ('dwTime', c_uint), ] def get_idle_duration(): lastInputInfo = LASTINPUTINFO() lastInputInfo.cbSize = sizeof(lastInputInfo) windll.user32.GetLastInputInfo(byref(lastInputInfo )) millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime return int(millis / 1000.0) class disable_file_system_redirection: _disable = windll.kernel32.Wow64DisableWow64FsRedirection _revert = windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value =c_long() self.success = self._disable(byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) seconds=get_idle_duration() m, s = divmod(seconds, 60) h, m = divmod(m, 60) d,h =divmod(h,24) print("System Idle time in DAYS:HOURS:MIN:SEC") print "%02d:%02d:%02d:%02d" % (d, h, m, s) if ( m>threshold_time or h>0): with disable_file_system_redirection(): ping = subprocess.Popen("rundll32.exe user32.dll, LockWorkStation",stdout=subprocess.PIPE,stderr = subprocess.PIPE,shell=True) out = ping.communicate() output = str(out) print output print 'System has been locked'
I don’t understand this part and I think I’m making a mistake here
- Please write your code on below box to create your own custom script condition.
- Please use "alert(1)" to turn on the condition (trigger an alert) and "alert(0)" to turn off the condition (disable an alert).
- Please define the custom alert text inside the code with "Print" function