Can't capture the screen
I have a windows service running on a client machine. I need to capture the client's screen and send it to the server via remote access. When I run the exe file, it can capture the screen and send it to the server. But when I run it as a service, it logs the following error:
"The pen is not valid."
The "interact with desktop" checkbox is selected. The code I'm using for the screenshot:
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 could be the cause and how can I solve it?
+2
source to share