![]() |
Desktop Development »
Desktop Gadgets »
General
Intermediate
License: The Common Development and Distribution License (CDDL)
pcNanny: Keep Track of What Your Kids are Doing on the ComputerBy milkplusKeep track of what your kids are doing on the computer |
C#, Windows, .NET, Visual Studio, WinForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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#.
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.
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.
To install the application:
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".
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;
}
sessionTimeUsed, and fixed reported error
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Jan 2009 Editor: Deeksha Shenoy |
Copyright 2007 by milkplus Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |