This project helps to create your own parental control service in C#. The current version will shutdown Windows if an unauthorized user (your kid) tries to boot the family PC during blockout period, say from 11 pm to 7 am.
My friend Alexander asked me if I can help him to control his kid's access to the family PC. I did some research on the Internet and found that there are many of those applications available but:
- You have to buy them
- They are too complicated for use and have too many options which I will never use
So, I decided to write my own application to help him. The idea was just to write a Windows service which will monitor the system clock and shut down the system if blockout time occurs. But an easy way for a kid to fix this is to change the system clock. This operation takes a little effort and could be done by any computer kid. So, our service has to fix the system clock whenever it's changed. To do that, we can use some Internet resources, say well known time saver
Using the Code
The project contains three main parts:
- Service Control Part ParentControl.cs, which checks the current system clock against the blockout period.
- Internet Time Synchronization Client NTPClient.cs (written by Valer BOCAN email@example.com).
- ExitWindows.cs which is just a C# wrapper for
ExitWindowsEx API call (original C++ code sample could be found here).
If the service cannot obtain time from the time server, it will shut down the computer as well. By default, the blockout period starts at 11 pm and ends at 7 am. You can specify different numbers as two parameters at the service start time. In the DEBUG version (only!) this service will ask if you want to shut down your PC or not. To make it possible, you have to check the "Allow service to interact with desktop" box when starting the service.
To install the service, you use InstallUtil.exe from the .NET Framework or call it from the command line with argument
To make the service self installable, I used a technique described in my other article (Windows Service which Kills Unwanted Windows).
Points of Interest
This project could be easily developed for different parental control services depending on what you need.
- First version uploaded March 31st, 2008