Sign in to follow this  
Followers 0
gear

This program can manage which program(s) can be run on PC

4 posts in this topic

I am new to AutoIt3.0, this is my first macro developed with AutoIt, hope somebody to make some comeents on the program and correction.

Thank.

Gear

;;This program can manage which program can be run on PC.At the start

;;The program will record the current running programs, without

;;the user's permission, no any other program run. If user wants to add one or some more

;; program that he wish to run, he can start the program and press

;; Ctrl+Left mouse click for some time, like 3 seconds, then this program will

;;add this new program to its running permission list.

#include <Array.au3>

#include <Misc.au3>;;since some function are use-defined function, so we must include these two files before runnnig program

$RemainWinsWithTitle=FindAllWinsWithTitle();; find all the current runnig program and regard them as user want to remian running ones

_ArrayAdd($RemainWinsWithTitle,"Windows 任务管理器")

Sleep(5000);;waiting for some time so that the program can record all the current runnnig program as into the remaining running list

While 1;; control the program will run continunely

$SecondAllWinsWithTitle=FindAllWinsWithTitle();;after some time, check if there is new window launches

$RemainWinCount=UBound($RemainWinsWithTitle,1);; the number that the user-permitted program list

$SecondWinCount=UBound($SecondAllWinsWithTitle,1);; the number of the current running program list

$HaveThisItem=TwoArraySameStringsQ($SecondAllWinsWithTitle,$RemainWinsWithTitle);; if the two windows list is the same, then skip,other wise find the difference and tries to close the new window

If IsString($HaveThisItem) Then;;if the return is the window title, close this window

Winclose($HaveThisItem)

Sleep(200);;waiting the window closed completely

EndIf

Sleep(500);;wait some time before next checking

;;when Ctrl is pressed, add the current active window to the remaining list, if it is a new window

If _IsPressed(11) Then

While _IsPressed(11);;waiting the program to launch completely. when the new program lauches completely, user should release the Ctrl key.

Sleep(50);;if the flesh-opening window is not in active state, please focus this new window by clicking on the window before releasing the Ctrl key, otherwise

WEnd ;;it will be closed by the program quickly.in order to add the new window into the remaining list, this new must be in active state at first

$WinToAdd=WinGetTitle(""); get the active window, due to the short time program sleeps, it narmally is the just launched window

$NewWinQ=MemberQ($WinToAdd,$RemainWinsWithTitle)

If $NewWinQ==0 Then ;;if it is a new window, adds it to the window list you want to remian

_ArrayAdd($RemainWinsWithTitle,$WinToAdd);; add this new window to the user-permiited program list

EndIf

EndIf

;;remove the non-existing window title(s) at present from the window remaining list that you wanted to remian before

;;undate the user-permitted runnnig program list, for user may close some window manually.

For $WinExist=0 To (UBound($RemainWinsWithTitle,1)-1)

$currentWinStringName=$RemainWinsWithTitle[$WinExist]

If ((Not WinExists($currentWinStringName)) And $currentWinStringName<>"Windows 任务管理器") Then;;Windows 任务管理器 can not be close, for user tries to use it to control this program

_ArrayDelete($RemainWinsWithTitle,$WinExist);; delete the user-closed window from program-remaining list

EndIf

Next

WEnd

;;THE FOLLOWING ARE THE USER-DEFINED-FUNCTIONS

;;following find all the windows with title at present

Func FindAllWinsWithTitle()

Dim $AllWinsWithTitle[200] ;;record all the windows with title the max number windows can be as big as 200

$var = WinList()

$nn=0;;please attention the position of "$nn=0", it must be placed before the FOR-NEXT loop

For $i = 1 to $var[0][0];; only the visible and the ones with titles will be monitored

;; Only display visble windows that have a title

If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then

;;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])

$AllWinsWithTitle[$nn]=$var[$i][0] ;;write a window with title

;;MsgBox(1,"This window",$AllWinsWithTitle[$nn])

$nn=$nn+1

EndIf

Next

ReDim $AllWinsWithTitle[$nn];;since only a few windows are in the remainng running program list, so redim the array

Return $AllWinsWithTitle

EndFunc

;;

Func IsVisible($handle)

If BitAnd( WinGetState($handle), 2 ) Then

Return 1

Else

Return 0

EndIf

EndFunc

;;find if the specified string is in the array

Func MemberQ($WinTitleString,$StringArray)

$WinIncluded=0

For $i=0 To (UBound($StringArray,1)-1)

If $StringArray[$i]==$WinTitleString Then

$WinIncluded=1;; it means the specified string is found in the string array

ExitLoop

Else

EndIf

Next

Return $WinIncluded;;0 means not found, 1 means found

EndFunc

;; compare if two array have the same strings, even if these strings are located in different positions

;;but their members are the same

Func TwoArraySameStringsQ($Array1,$Array2)

$IfSameQ=1

For $i=0 To (UBound($Array1,1)-1)

$StringInArray1=$Array1[$i]

$IfSameQ=MemberQ($StringInArray1,$Array2)

If $IfSameQ==0 Then ExitLoop

Next

If $IfSameQ==0 Then

Return $StringInArray1;;return the title that the $Array2 does not include

Else

Return 1;; if 1, it means the two string array are the same

EndIf

EndFunc

Share this post


Link to post
Share on other sites



Idea is quite good.

Ive run that project some time ago and approached it a little different. i created a gui allowing the user to insert process names he wanted to allow.all others were closed imidiately. basically same thing.

a few tips for you:

1. use code tags when posting code

2. The line "Sleep(5000);;waiting for some time so that the program can record all the current runnnig program as into the remaining running list" is not necessary. the programm is not gonna jump to next step until the previous one is done. so sleep() is usually used to releaf the cpu or if u need the programm to wait a certain time.

Share this post


Link to post
Share on other sites

Did AutoIt understood it with unicode characters? =O

That's interesting, what encoding is the script using?


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

It may be useful when some managers and boosses try to strict his(her) employees to use PC to chat or browsing pages to pages, just for wasting time. Fathers and mothes also can strict their children not to use some program.

Gear

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