Sign in to follow this  
Followers 0
logonui

Help with continuously looping script

6 posts in this topic

#1 ·  Posted (edited)

Hi People,

I work in a school and I am trying to write a program that bans certain programs from access by the kids like chat clients. I have worked out how to do this but every program has to have its own exe file.

I am now trying to put all of the banned apps in a single txt file.

This is what i have come up with so far

#include<File.au3>

If Not FileExists("\\shc4\Student\Users\Students\INetBans\Filebans.txt") Then
    _FileCreate("\\shc4\Student\Users\Students\INetBans\Filebans.txt")
EndIf

$LineCount = _FileCountLines("\\shc4\Student\Users\Students\INetBans\Filebans.txt")

For $Prolist = 0 to $LineCount
    FileOpen("\\shc4\Student\Users\Students\INetBans\Filebans.txt",9)
    $Line = FileReadLine("\\shc4\Student\Users\Students\INetBans\Filebans.txt",$ProList)
    ProcessWait($Line)
    If ProcessExists($Line) Then
        ProcessClose($Line)
    EndIf
Next
Exit

The problem is that it will only look at one line at a time I need it to look for all of the lines at once as I don't know what order the kid is going to try using them. And help would be greatly appreciated as I am now tearing my hair out

Cheers

logonui

Edited by logonui

Share this post


Link to post
Share on other sites

I personally think black lists like this are difficult to maintain and easy to bypass, but to do what you want is not hard. It will be easier if you just read the whole file to a single string and use StringInStr() to test for it:

Global $sBanFile, $sBanList, $avProcs
$sBanFile = "C:\Temp\Filebans.txt"
$sBanList = FileRead($sBanFile)
$avProcs = ProcessList()
For $i = 1 To $avProcs[0][0]
    If StringInStr($sBanList, $avProcs[$i][0]) Then
        MsgBox(16, "Banned Process", "Banned process found: " & $avProcs[$i][0])
        ProcessClose($avProcs[$i][1], 1)
    EndIf
Next

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Maybe use Group Policy???

Group policy isn't that reliable here and as I am not the guy that deals with the servers it is out of my hands

It will be easier if you just read the whole file to a single string and use StringInStr() to test for it

This works great Cheers, I have been trying to run the code so that it looks for the program launching before it goes through the motions e.g.

ProcessWait("iexplore.exe" Or "firefox.exe")

but this does not seem to work (it was a long shot anyway) otherwise I have to have the script looping continuously, I don't really want to do this for obvious reasons. If I was looking for just one program then it would not be a problem but this needs to be able to run all day every day.

Cheers

Share this post


Link to post
Share on other sites

built on what PsaltyDS came up with, this should work.

it refreshes the list every 24hours (unless i did some math wrong)

Global $sBanFile, $sBanList, $avProcs,$tc
$sBanFile = "\\shc4\Student\Users\Students\INetBans\Filebans.txt"
$sBanList = FileRead($sBanFile)
$tc=TimerInit()
While 1
    $avProcs = ProcessList()
    For $i = 1 To $avProcs[0][0]
        If StringInStr($sBanList, $avProcs[$i][0]) Then
            ;MsgBox(16, "Banned Process", "Banned process found: " & $avProcs[$i][0])
            ProcessClose($avProcs[$i][1], 1)
        EndIf
    Next
    Sleep(500)
    If TimerDiff($tc) >= 86400000 Then
        $sBanList = FileRead($sBanFile)
        $tc=TimerInit()
    EndIf
WEnd

people are anoying, am i? ;) v2.95

Share this post


Link to post
Share on other sites

i like using this:

$i = 0

while $i <= [whatever # you want]

$i = $i + 1

;code

;code

wend

that way, it will loop it as many times as you want

if you want it to be like the neverending story, delete the $i = $i +1 line and there you go.

it works every time for me.

hope it helps you


Education: Francis Tuttle Technology Center adult full-time studentCourse of study: Network TechnologyCurrent Course: Microsoft Windows Server 2003, Enterprise EditionCompleted Courses: CompTIA A+ Hardware and Software, Windows XP Professional, Microsoft Office 2003, Desktop Support and Troubleshooting, and CompTIA Network+Remaining Courses: Linux Administration, Copper Cabling, Microsoft Windows Server 2003, Enterprise EditionAchievements: @17 years old, scored 98th percentile U.S. in Algebra 2 and Advanced Chemistry. [i.e. Ranked top 2% in the nation of High School students]

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