Sign in to follow this  
Followers 0
Eagleeye

Prevent user from closing script

5 posts in this topic

It is likely that this question has already been answered somewhere on this forum, and that I am just search-tarded. Though I was unable to find an answer.

How do I keep a script from being closed by a user? The user will not have administrator rights on the computer.

I am trying to come up with a solution to for a larger script that blocks input from a user at scheduled times. It is also possible for me to run the script every five minutes or so; therefore, I wouldn't have to worry about the user closing the script. This arouses another question though because during testing of this method, BlockInput() would only function while the script was running.

Anyway, any suggestions are greatly appreciated. The script so far is:

CODE
#include<Date.au3>

HotKeySet("{ESC}", "Terminate")

Global $mySchedule = 0

local $myFileName = "Schedule.ini"

ProcessIni($myFileName)

ProcessSchedule($mySchedule)

; !!!!!! don't forget to add a 'B' to the beginning of these before you push this script out

Func ProcessIni($fileName)

; Precondition: $fileName contains the location of a properly formatted ini file, and this script is being run on a computer with "B***" in its name

; Postcondition: $mySchedule has been formatted to contain the days that the appropriate computer is to be locked

local $thisComputer = StringSplit( @ComputerName, "-")

if($thisComputer[2] = "140") Then

$mySchedule = IniReadSection( $fileName, "dp-140")

EndIf

if($thisComputer[2] = "142") Then

$mySchedule = IniReadSection( $fileName, "dp-142")

EndIf

if($thisComputer[2] = "212") Then

$mySchedule = IniReadSection( $fileName, "dp-142")

EndIf

if($thisComputer[2] = "Proto01") Then

$mySchedule = IniReadSection( $fileName, "test")

EndIf

EndFunc

Func ProcessSchedule($Schedule)

; Precondition: $Schedule contains a 2 dimensional array containing the days [n][1] and times [n][2...p] that a particular computer is supposed to be locked

; Postcondition: The computer is locked if it is supposed to be and unlocked it if isn't

; Format and get current time

local $startEnd

local $locked = 0

local $currentTime = _NowTime(4)

$currentTime = StringReplace( $currentTime, ":", "")

; Add an entry to startEnd if there are times for today

if Not StringInStr($Schedule[@WDAY][1], "NULL") Then

; Format startEnd times

$Schedule[@WDAY][1] = StringReplace($Schedule[@WDAY][1], " ", "")

$startEnd = StringSplit($Schedule[@WDAY][1], ",-")

EndIf

; convert the values in startEnd to integers

for $i = 1 To UBound( $startEnd, 1 ) - 1 Step + 2

; MsgBox(1, "test2", $startEnd[$i] & "-" & $startEnd[$i+1] & ":" & $currentTime)

if (($currentTime >= $startEnd[$i]) AND ($currentTime <= $startEnd[$i+1])) Then

BlockInput(1)

MsgBox(1, "test", "This computer should be locked right now!")

$locked = 1

ElseIf ((($currentTime <= $startEnd[$i]) OR ($currentTime >= $startEnd[$i+1])) AND ($locked <> 1)) Then

MsgBox(1, "test2", "Unlocking computer now")

BlockInput(0)

$locked = 0

EndIf

Next

#cs NOTE: Use this code if we decide to keep the script running at all times

$a1 = StringLeft($value[1], 2) ; hours

$b1 = StringRight($value[1], 2) ; minutes

$a2 = StringLeft($value[2], 2) ; hours

$b2 = StringRight($value[2], 2) ; minutes

$a = $a2 - $a1 ; hours

$b = $b2 - $b1 ; minutes

if($b < 0) Then

$b = $b + 60

$a = $a - 1

$a = $a - 1

EndIf

$a = $a * 60 * 1000

$b = $b * 1000

MsgBox(1, "test2", $a & " " & $:P

$interval = $a + $b

Sleep($interval)

#ce

EndFunc

Func Terminate()

Exit 0

EndFunc

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Disclaimer: This is not intended to be a bump, I cannot edit my op.

An adequate solution would also be to figure out a way to have BlockInput (or a similar function) function while the script is not running, and be able to turn it off the next time the script runs.

Edited by Eagleeye

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is it necessary for the user to see the screen while the script is running? Or would a scheduled event that ran a script to lock the PC while the script ran and then unlock it afterward suffice? You could throw up the "marquee" screensaver while locked with a message stating "PC unavailable until..."

Of course, you, knowing the screensaver password, could always break in.

Edited by Spiff59

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for replying, Spliff59.

No, it is not necessary for the user to see the screen while it is running. In fact, the entire idea behind the script is to prevent the computer from being a distraction in a classroom, so a blank SS would be preferable.

I like your idea, and am going to try to implement it. A screen saver seems to be more manageable than BlockInput(), which can be overridden with Alt+Ctrl+Delete.

EDIT: Unfortunately we are already utilizing a screen saver to log off idle users, WinExit.scr, which cannot be password protected. So, we're back to BlockInput() not being robust enough to actually completely prevent someone from using the computer, I think.

Edited by Eagleeye

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

EDIT: Oops I posted the same thing twice... sorry. Please delete this post moderator.

Edited by Eagleeye

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0