title: Cannot capture screen
body: <p>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:</p>
  
  <p>"The handle is invalid."</p>
  
  <p>The service's "interact with desktop" checkbox is checked. The code I am using for screenshot is:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>What may be the cause and how can I resolve this?</p>