protected override void OnStart(string[] args)
{
base.OnStart(args);
CaptureScreen();
}
protected override void OnStop()
{
base.OnStop();
}
private void CaptureScreen()
{
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
printscreen.Save(@"L:\" + Counter++ + ".jpg", ImageFormat.Jpeg);
}
- I checked interact with desktop
- tried the the localService account & user
The service is "headless", no UI and without being a 100% sure (The documentation for CopyFromScreen is rather vague) I'd expect that to fail when running headless. How would the service know which screen to copy in the case where multiple users are logged on at the same time?
see this questions as well
You need to set your service to the users windows station. This is not my code and I can't remember where I got it from. Add these two classes then you can create a Desktop object
Desktop userDesk = new Desktop();
Then when you need your service to interact with the user session you would write
userDesk.BeginInteraction();
and finally to return to your service's session you call
userDesk.EndInteraction();
In the case of XP/2003 the Interact with Desktop should help. In the case of Windows 7/Windows 2008 an Interact with Desktop works differently.
The best solution for you would be to analyze logon sessions from the service and, for new session, start the "desktop" process in user session and communicate with that process to get screens.
This is part of the session 0 isolation feature that was added to Vista. Services now run their own session with their own workstation and desktop. Much like the session that the login prompt and screen saver run in. You are taking a screenshot of that session's desktop, there's nothing in it. Getting access to the user desktop is no longer possible. It is a security feature, it prevents shatter attacks. Admittedly, I don't understand why the 'interact with desktop' checkbox wasn't removed.
You'll need to change your program to run as a "windows application", not a service. Put a shortcut in the Startup folder or use the Run registry key. Which is okay, there's nothing much worth snapping when no user is logged in.