help with tracking script

Hello,

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()[0]
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

Note:

  • 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

Hi @hguler07,

Thanks for reaching us. Our script developers have modified and prepared this script in JSON format.
Please try this and provide your feedback.

Kind Regards,
PremJK

20200908-idle_screen.json (2.46 KB)

Hello, my English is bad, maybe I may have explained it wrong. I will try to explain with screenshots, Actually this your code is working. It locks my screen.

The code you see in this picture

I want to run this code in this part.

I’m pasting the running code into this field

This way I am getting an error.

what i want to do, This code running instantly. By having it constantly checked on the back every minute. I want to lock the screen of the computer of non-computer users.

But I could not run the code.

I tried the code you shared with me as normal. I couldn’t run it :frowning: . Maybe I’m making a mistake. But the code you wrote above works.

Hi @hguler07,

Thanks for providing your feedback. We have asked our script developers to check your comment and provide their input.

Kind Regards,
PremJK

Hi @hguler07,

Please pass the new code provided by our script developers in
https://i.hizliresim.com/W8hXkY.png

After that if you try again, there won’t be any error.

Please try and provide your result.

Kind Regards,
PremJK

I get the same error again. I’m just pasting this code as it doesn’t meet the requirements.

Picture

The code I pasted 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()[0]
output = str(out)
print output
print 'System has been locked'

When I say add script, this is the code on the page that opens, I delete it and write the above code. But I get an error because the alert parts are missing. I just want a code that I can paste and use.


# The script is a template to check UAC status on device.
import os
import sys
import _winreg

def alert(arg):
sys.stderr.write("%d%d%d" % (arg, arg, arg))

# Please use "alert(1)" to turn on the monitor(trigger an alert)
# Please use "alert(0)" to turn off the monitor(disable an alert)
# Please do not change above block and write your script below

def checkUAC():
if 'PROGRAMW6432' in os.environ.keys():
handle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Policie s\System", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)
return (_winreg.QueryValueEx(handle, "EnableLUA")[0])
else:
key = getattr(_winreg, "HKEY_LOCAL_MACHINE")
subkey = _winreg.OpenKey(key, "Software\Microsoft\Windows\CurrentVersion\Policie s\System")
return (_winreg.QueryValueEx(subkey, "EnableLUA")[0])

checkUAC()
if checkUAC() == 0:
alert(1)
print 'User Access Control has been disabled and system becomes less secured'
else:
alert(0)
print 'User Access Control has been enabled'


Hi @hguler07,

We are sorry for the issue. We have asked our script developers to look into this and update you.

Kind Regards,
PremJK

Hi @hguler07,

Our script developers analysed and it seems new code provided by our script developers are not pasted.

After pasting new script file,

Can you please confirm that and try again.

Check this wiki link to guide how to use the monitors
https://wiki.itarian.com/frontend/web/topic/how-to-use-monitors-to-track-endpoint-performance

Kind Regards,
PremJK