Monthly Archives: January 2014

Creating screen scraper that works in background

Recently I needed to share information which I could effectively do only by capturing screen and uploading the screenshot to a public location. This kind of things cause my primitive laziness instinct to kick in and I start grasping for automated solution. I say primitive instinct because automation effort in most cases takes more time than performing the work by hand. But that is a topic for a longer post, so I’ll go back to my problem.

There are few tools which provide functionality of capturing part of a screen and uploading result to a hosting service, which is nice but doesn’t solve my problem completely. Additionally, I needed to do screen capturing at set time intervals, navigate to a different window and send out the link after image has been uploaded. Perfect, I thought! I’ll fire up Visual Studio and write something up! I won’t go into details of how to do all this, as it’s not technically interesting (I might publish source code in the future). Main problem which I initially didn’t think about was, how to do screen capturing of specific window without using a dedicated machine for this task. Using the tool in my user session is clearly not a solution since I don’t want to share random state of my screen, but specific windows at specific times.

Idea 1
Create Windows user account and keep it logged in in the background.
Failed because Windows doesn’t do any drawing once user session goes to background.

Idea 2
Log into Remote Desktop session and close the connection without logging out.
Failed for same reason as idea 1. Even if you ignore that you need Windows Server OS and appropriate license to have multiple RDP sessions at the same time, problem of idea 1 remains. This idea might have worked if I had access to a Windows Server newer than Windows 2000.

Idea 3
Host a virtual machine in Hyper-V.
Success! Worked like a charm in first attempt! Things to remember are that you must connect to the machine using Hyper-V VM Connection and not RDP, that Hyper-V video driver supports resolutions only up to 1600×1200. This solution seems obvious, but when you’re working on such seemingly simple problem, first solution that comes to mind isn’t to get a dedicated machine or sacrifice CPU and memory of your machine to host a VM. But thanks to Moores law I was able to accept that it’s cheaper for me to give up 512MB of RAM than to spend a week trying to come up with an elegant solution (and probably failing).