Click here to Skip to main content
Licence CPOL
First Posted 3 Jul 2008
Views 35,855
Downloads 264
Bookmarked 56 times

How to kill processes running on a computer in your home

By Xiangyang Liu 刘向阳 | 19 Jul 2008
A small ASP.NET program to help control your child's game playing.
1 vote, 6.3%
1
1 vote, 6.3%
2

3
5 votes, 31.3%
4
9 votes, 56.3%
5
4.71/5 - 16 votes
2 removed
μ 4.41, σa 2.07 [?]

Introduction

Like 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.

  1. An ASP.NET program that allows you to kill selected programs on another computer if these programs have been running for too long. You get to define how long is "too long".
  2. A little client program to make sure that your ASP.NET program is running even after rebooting the machine.

The programs you want to control are defined in the web.config file, like the following:

<appSettings>
<add key="GameList" value="firefox.exe,60,60;iexplore.exe,60,60" />
</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 the executable file, and the second, the number of minutes you allow the program to run. In this case, the application will kill all Firefox and Internet Explorer processes 60 minutes after they were detected. The third part is the number of minutes the 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, and the third part is called GameDelay.

You don't have to specify the 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 the folder path instead of the 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 Killer

This 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:

  1. Unzip the files into a folder on the target machine.
  2. Create a new virtual directory pointing to the GameKiller subfolder.
  3. If you have more than one version of the .NET Framework on this computer, make sure the virtual directory is configured to run with .NET 1.1.
  4. Change the machine.config file of .NET Framework 1.1 so that it has "SYSTEM" privilege. This can be done by finding the ProcessModel element in the machine.config and replacing the value of the userName attribute with "SYSTEM".
  5. Set the folder permission properly so that non-admin users won't be able to delete or modify the files belonging to this application.

Yes, #4 above is necessary because otherwise the application won't be able to detect and kill other running processes.

Assumptions:

  • You are doing this on one of your home computers behind a firewall.
  • Your computer has .NET Framework 1.1 installed and IIS enabled.
  • Your child does not have the necessary knowledge and skill to play the same trick on you (yet).

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:

PingClient.exe http://localhost/GameKiller/Ping.asmx

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 time values from the GameList setting in the web.config file and stores the information in an internal array list. Then, it will start a background thread which calls Process.GetProcesses to retrieve all the running processes periodically.

For each running process, the application will check if it is one of the programs defined in the 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 the 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 Interface

The 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 the processes running on the computer. It lists the process ID, time (the number of minutes the process has been running), and the 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 the programs located in 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 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 textbox 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, the 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 will 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 textbox 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 anymore and you have 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.

History

  • 7/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 the clock is set backward or forward. If it is, then all the controlled programs will be killed immediately.
  • 7/7/2008:
    1. Added the "How does it work?" section.
    2. Updated source code to add the following feature: Now each program defined in the web.config file can has its own delay time. If "MyGame.exe,5,10" is an item in the GameList setting, then MyGame.exe will be allowed to run for 5 minutes; after the time is up, the user has to wait for another 10 minutes to run it (to avoid being killed). If only "MyGame.exe,5" is specified in the web.config file, then the global GameDelay setting will be used instead.
  • 7/5/2008:
    1. Added the Filter and Reverse Filter buttons.
    2. Modified how the Add button works. You can add multiple items at once.
    3. Writes data to hard disk when the application is shutdown, the data will be read into the application when it starts up (without this rebooting, the machine will get around the control implemented in the application).
    7/3/2008: Initial version posted.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Xiangyang Liu 刘向阳



United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood Pinmemberdxlee9:42 7 Oct '09  
Generalgood article Pinmembervegeta4ss8:07 9 Jul '08  
GeneralRe: good article [modified] PinmemberXiangyang Liu10:51 9 Jul '08  
GeneralWindows Service PinmemberMember 190497011:48 7 Jul '08  
GeneralRe: Windows Service PinmemberXiangyang Liu12:07 7 Jul '08  
QuestionWhat would happen... PinmemberWist9:19 7 Jul '08  
AnswerRe: What would happen... PinmemberXiangyang Liu11:40 7 Jul '08  
GeneralAnother way... Pinmemberbcraun17:14 3 Jul '08  
GeneralThe point is ... (Re: Another way...) PinmemberXiangyang Liu17:55 3 Jul '08  
GeneralRe: The point is ... (Re: Another way...) Pinmembershadyscience@yahoo.com0:53 21 Jul '08  
ya

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 19 Jul 2008
Article Copyright 2008 by Xiangyang Liu 刘向阳
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid