views:

231

answers:

2

I need to write a .NET application that captures screenshots of various web pages periodically. The application needs to run as a windows service in unattended mode - when there is no user session or when the workstation is locked. A situation similar to: (http://stackoverflow.com/questions/1445788/c-screenshot-of-process-under-windows-service), only, I need to do this on web pages rather than processes.

When I try to use PrintWindow API, I am able to capture inactive or hidden windows, but get a black image when the workstation is locked. Tried this approach (www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic34231.aspx) but doesn't work.

I know this is possible since there are apps like WebShot (www.websitescreenshots.com) that are able to do it - capture screenshots of web pages even when the workstation is locked or when it runs as a service.

What am I missing? How do I get this to work?

Thanks much for your time.

Edit: More on my approach - I'm using the .NET WebBrowser control created programmatically. I load the webpage in the browser control and capture the image from it using the PrintWindow API. This I'm able to do whether the control is visible or not, but it trips me up when the workstation is locked.

+1  A: 

BrowserShots (http://browsershots.org/) is an open source application that seems to have similar goals to you - they may already have solved your problem. Unfortunately their site seems a bit broken at present.

Colin Pickard
A: 

Since you are only rendering websites and not getting screenshots of different programs you could try WebBrowser.DrawToBitmap.

That way you would wouldn't have to worry about login state

http://thepursuitofalife.com/the-missing-drawtobitmap-function-in-the-net-webbrowser-class/

OG
Thanks, I tried that, but it works only when there is a user session in progress - not when it runs as service or when the workstation is locked.
Karun