|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionLike many other teenagers, my son spends too much time playing games and chatting with his friends online. Failing to get him to listen to me, I started to write a program that controls his computer. I hope you will never need to do the same. But for those parents who like the idea, here is what I came up with.
The programs you want to control are defined in the web.config file, like the following: <appSettings>
As you can see, the value of GameList is a list of semi-colon delimited items. Each item has three parts separated by comma, the first part is the name of executable file, the second the number of minutes you allow the program to run. In this case, the application will kill all Fire Fox and Internet Explorer processes 60 minutes after they were detected. The third part is the number of minutes user has to wait before he/she can run the killed programs again. If a killed program is started before the waiting period ends, it will be killed again. The second part is called GameTime, the third part is called GameDelay. You don't have to specify time values for each program. If you only have the executable names for some programs listed in GameList, then by default each of such programs is allowed to run 30 minutes and after that the user has to wait for 120 minutes. You can change the default values by defining GameTime and GameDelay in the appSettings section of the web.config file. By default the application checks for programs defined in GameList every 15 seconds. The value of CheckInterval can be used to specify a new value (number of seconds). To prevent users from renaming executable files to get around the restriction, you can specify folder path instead of executable name in GameList. For example, if the string c:\mygame\ is listed in GameList, then all programs in folder c:\mygame will be under control. The Game KillerThis is an ASP.NET 1.1 web application. You have to install it on the computer you want to control. Here are the steps to install:
Yes, #4 above is necessary because otherwise the application won't be able to detect and kill other running processes. Assumptions:
What if the machine you are trying to control does not have IIS? You can enable IIS on Windows XP Media Center Edition or Windows Vista Home Premium Edition. If you have Windows XP Home Edition, there is a way to install IIS on it if you have the Disks for Windows 2000 (I don't remember the details, you can easily google it). How do you make sure the above ASP.NET application is running all the time, even after reboot? This is what the included PingClient.exe is for. All you have to do is schedule the following command to run at the start of the computer:
The URL above is pointing to a web service within the ASP.NET application. How Does It Work?When the application starts up, it will read the list of programs and the corresponding times values from the GameList setting in web.config file and store the information in an internal array list. Then it will start a background thread which calls Process.GetProcesses to retrieve all running processes periodically. For each running process, the application will check if it is one of the programs defined in web.config file. If it is, the time of detection will be stored into an internal hash table. If the same program is detected again after the allowed time (since its first detection), it will be killed by the application. Even if user restarts the program, it will be killed again until the time period specified in the GameDelay setting has passed. Suppose a program is allowed to run for one hour. The user may run it for 59 minutes, reboot the machine and run it again, hoping to get another full hour's time. However, this trick won't work because the above internal hash table (which contains information on when a controlled program was first detected) will be saved to hard disk when the machine is shutting down. The data will be read into the internal hash table when the application starts up again. The application also has code to guard against setting the clock backward or forward. User InterfaceThe main work is done in the background thread of the web application. However, the application does have a user interface. Here is what the GameKiller.aspx page looks like:
Display: This page displays all processes running on the computer. It lists process id, time (the number of minutes the process has been running), and file path for all processes. If you click the Display button, the list will be refreshed. Filter: If you enter text into the Input text box and click this button, then only the processes whose paths contain the text you entered will be displayed. For example, if you want to see only programs located on the two folders D:\MyGame1 and D:\MyGame2, you can enter D:\MyGame1\;D:\MyGame2\ and click the filter button. Note that the two filter strings are separated by semi-colon. Reverse Filter: This button does the opposite thing as the Filter button. If you don't want to see programs in the c:\windows and c:\backup, you can enter c:\windows\;c:\backup\ into the Input text box and click this button. Add: You can dynamically add a new program into the list of programs you want to control from this page. For example, if you type NewGame.exe,5,30 into the Input text box, and click the Add button. Then NewGame.exe will be controlled and it will be allowed to run at most 5 minutes, and after that user has to wait for 30 minutes before running it again. If the program you want to add is already being controlled, then only the time values will be updated. However, the changes made with the Add button wil not be written into the web.config file, therefore it will be lost after rebooting the machine. Kill: The Kill button kills a process immediately. All you have to do is type the process id into the Input text box and click the button. Restart: This button restarts the background thread within the web application. From the above picture you can see that the inetinfo.exe process is listed with process id 3400. What will happen if you kill that process? Well, it means the web application won't be running any more and you are given your child the freedom to play any game he/she wants for however long he/she wants, until the machine is rebooted! The real version of the program I use at home has some other features and the GUI won't work without proper authentication. For simplicity I did not include everything in the published version. History7/19/2008: Updated code and article text. Fixed bugs in previous version. Added the new feature of specifying GameTime and GameDelay for each individual program defined in GameList. 7/9/2008: Added code to detect whether clock is set backward or forward. If it is, then all controlled programs will be killed immediately. 7/7/2008:
7/5/2008:
7/3/2008: Initial version posted.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||