Introduction

Some time ago, I needed to capture a certain computer's desktop in order to find out what that user is doing every day. So, I made a .NET 2.0 Winforms Application which stays on system tray (optional) and capture the desktop in given time interval (say every 60 secs) and emailed the captured images to me as message attachment (say every 30 mins). It ensures the captures are small enough and embedded inside HTML email so that I don't need to open hundreds of attachments and see the screenshots. I could just read through the email and see the captures made. You will find this application quite handy in many use cases including:

Keep an eye on employees who spend too much time on web or chatting. See what they really do.

Keep an eye on your better half in case s/he is cheating on you.

Keep an eye on your teenagers and see how they use the computer. Find the amount of time they browser porn on web.

All you do is sit back and relax in your office and the app informs you every 30 mins via email what your subject is doing on the computer. You don't need to worry about missing some captures when you are away from your computer. It will be safely kept in your inbox and you can go through all the captures on your weekend.

Please note, this is a surveillance application and by nature it violates privacy policy. So, you are solely responsible for whatever way you use it.

How to Use the Application

Configure the following settings from the Visual Studio Settings Designer (if you have Visual Studio):

Configure the path where the screenshots will be stored. Then configure the duration, default is every 1 minute, one screenshot is taken. "To" contains the email address of yours. Use free email services because very soon you will find it's filled up. Username and Password is for the SMTP authentication. "SMTP" contains the SMTP Server name or IP. "MailSendDelay" is the delay between sending emails.

All you need to do is build the app and run it once on the computer which you want to keep an eye on. It will hide itself on the system tray as a harmless icon and register itself on the startup and start capturing immediately. After a week or two, cleanup the "C:\temp" folder where the screenshots are kept.

You can also configure the properties at run time after running it once on a computer. This is for those who does not have Visual Studio in order to configure the settings before building it.

In order to launch the configuration dialog box while the application is running, find the icon on the system tray and click mouse buttons exactly in this order:

Press and hold left and right mouse button on the system tray icon one after another

Release only the right mouse button while holding the left mouse button down

This will bring up the configuration dialog:

Here you can make changes while it is running.

Once the application is run on a PC, it will register itself in the startup. So, every time Windows starts, it will load the application automatically and start taking screenshots.

Let's learn some interesting stuffs from this application:

Prevent Closing the Application When Close Button is Clicked

The spy application needs to keep on running all the time. So, we need to prevent it from closing. In order to keep the application running, one window must remain loaded and hidden. So, that window's FormClosing event must cancel the close event.

The window is also made hidden and not to appear on the taskbar. You can turn off ShowInTaskbar property from the Form's properties. The Properties window is kept alive all the time hidden and moved away from visible area.

Capture Screenshot of Desktop

The following code can take a screenshot of the whole screen. It only takes primary screen's screenshot. If you have multiple monitor, then you need to capture them individually.

First a bitmap object for the whole screen size is created and then the graphics from the screen is copied to the Bitmap object.

Convert the Bitmap to Low Resolution JPEG

A desktop screenshot is a large picture and can easily size about 300 KB when converted to JPEG regular mode. If you have high resolution like 1600X1024 or more, the screenshot size will be even bigger. If such large files are emailed to you as attachment, it will be a real pain for you and your mail server. So, you need to convert the bitmap to a low quality JPEG.

How to Email the Pictures as Embedded Image in HTML Format

You can email the pictures as regular attachment. But that makes looking at those screenshots very difficult as you have to double click on each and every attachment. A better approach is to create an HTML formatted email body where the screenshots are embedded one after another. Thus you can just read the email with the screenshots and see every thing that has been captured at one glimpse.

The last line starts an HTML formatted email body. We are going to construct an HTML mail where the images will be inline. The tricky part is to build the body of the message. The body requires that we create <img> tag for each image inside the body in this format:

<img src=cid:ID_OF_THE_IMAGE />

The ID needs to be the ContentID of the LinkedResource instance which is created for each image. Here's the code:

I keep a counter for the last capture file name and the last emailed file number. Then for each capture file which has not been emailed yet, I create a LinkedResource for the image and then add it in the resources list. I also build the body of the message which contains the <img> tag with the LinkedResourceContentID.

Then we create something called AlternateView for the message body which says the message has an HTML view:

After this, the email is sent asynchronously so that the screen capture process does not get stuck. It generally takes a while to send the image with all the screenshots embedded. So, you can't do this synchronously.

How to register application to start at startup

I have a handy RegistryHelper class which can register a path in the system registry at Software\Microsoft\Windows\CurrentVersion\Run location. Whatever you put there, Windows launches it at startup. I found this code somewhere on the web long time back. Not sure who's the original author.

Conclusion

This is a very low footprint easy to use desktop capture and email utility. Once it's run in a computer, it will keep capturing screenshot of all users on that computer and email to you periodically. All you need to do is skim through those emails every now and then and see what your subject is doing. Please note, this is a surveillance application and by nature it violates privacy policy. So, you are solely responsible for whatever way you use it.