I have a windows service running on a client machine. I need to capture the screen of the client and sent it to server over the remoting. When I run the exe file, it can capture the screen and send it to the server fine. But when I run it as a service, it logs the following error:
"The handle is invalid."
The service's "interact with desktop" checkbox is checked. The code I am using for screenshot is:
Image bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
return bmpScreenshot;
What may be the cause and how can I resolve this?