Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

pcNanny: Keep Track of What Your Kids are Doing on the Computer

0.00/5 (No votes)
6 Jan 2009 1  
Keep track of what your kids are doing on the computer

Overview

As a parent, I wanted to set limits on how much time my kids could spend on the family computer. I couldn't find anything simple and free to do this, so I wrote it myself in C#.

Requirements

This application only works if your family has a single shared PC computer where each person has their own account and only parents have "admin" accounts.

It should run under Windows 98/XP/Vista with .NET Framework 2.0 or later.

Features

  • Keeps track of how much time your kids spend on the computer
  • Allows you to set time limits for each day of the week
  • Nags your kids when they exceed their time limit (popup every 3 minutes)
  • Optional key logger so you can see what your kids say online*

DISCLAIMER: *This app includes an optional key logger to allow parents to see what their kids are saying online. I strongly discourage anyone from monitoring any computer that you do not own or do not have intellectual property rights over. It is illegal and punishable as a crime under (state law) to intercept electronic communications.

Quick Start

To install the application:

  1. Create a program folder and copy the binaries there - C:\Program Files\pcNanny
  2. Copy a shortcut into the "Start Menu" for all users - C:\Documents and Settings\All Users\Start Menu

Since the EXE stores data in the same folder as the EXE, it needs to be in a folder where all users can have write access. That is, somewhere like "Program Files".

How? (Reading the Code)

My first version of this program only showed the login time for the person logged in. This resulted in everyone sneaking up and "checking" the screen to see how much time the person sitting at the computer had used. That seemed dumb, so this version shows the login time of everyone in the family. We can all monitor each other.

For each user account, I keep track of time used, along with other information. When the application starts, if the date has changed, I reset the time used.

class UserInfo
{
    static public IniFile file = null;

    public string name = "Anon";
    public TimeSpan timeLimit = new TimeSpan(1, 0, 0); // 1 hour
    public TimeSpan timeUsed = new TimeSpan(0, 0, 0);
    public DateTime startDate = DateTime.Today;
    public bool loggedOn = false;
    public bool screenSaved = false;
    public bool screenLocked = false;

After you reach your time limit (the default is one hour), the graphic changes from green to red, and the window will come to the front every three minutes to annoy you.

//
// Annoy user after we are over time limit by
// bringing window to front every 3 minutes.
//
if (user.IsOverTime() &&
    (user.timeUsed.Minutes % 3) == 0 &&    // every 3 minutes
    user.timeUsed.Seconds < 5)    // annoy for 5 seconds
{
    Rectangle bounds = Screen.PrimaryScreen.Bounds;
    this.Left = (bounds.Width - this.Width) / 2;
    this.Top = (bounds.Height - this.Height) / 2;
    this.WindowState = FormWindowState.Normal;
    this.TopMost = true;
    this.Show();
}
else
{
    // if not being annoying, allow other windows to come to the front
    this.TopMost = false;
}

At first, I used voice samples, but the kids just hit mute and forgot about it. A three minute snooze seemed reasonable.

I don't want the kids to close the application, so I disabled the close box. Since they are not "admin" accounts, they can't run the Task Manager and shut it down that way.

// Get rid of control boxes
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;

// Disable close window unless ending session
this.Closing += 
  new System.ComponentModel.CancelEventHandler(this.OnClosingEvent);

private static int WM_QUERYENDSESSION = 0x11;
private static bool systemShutdown = false;

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_QUERYENDSESSION)
    {
        systemShutdown = true;
    }
    base.WndProc(ref m);
}

private void OnClosingEvent(object sender, 
             System.ComponentModel.CancelEventArgs e)
{
    if (!systemShutdown)
        e.Cancel = true;
}

I still need to handle the logon events such as screensaver start/stop and display lock/unlock. For those, I used some code by Richard Arthur in the .NET Journal.

self = this;    //used by SensLogon event handlers

SensLogon.StartScreenSaver += 
    new SensLogonEventHandler(SensLogon_StartScreenSaver);

private static void SensLogon_StartScreenSaver(string userName)
{
    UserInfo user = self.GetUser(userName);
    user.screenSaved = true;
}

History

  • 6 September, 2007 - Created
  • 13 May, 2008 - Added bar graph, all users, and screensaver + screenlock events
  • 10 July, 2008 - Improved annoy code, added sessionTimeUsed, and fixed reported error
  • August 2008 - Added key logger
  • 3 January, 2009: Updated article

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here