0

I'm trying to execute the following code in a Windows Console Application.

using (Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb))
    using (Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot))
    {
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

        Bitmap b = new Bitmap(bmpScreenshot);
        b.Save("image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    }

However, this gives me the following error:

A Generic error happened in GDI+ at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   ved System.Drawing.Image.Save(String filename, ImageFormat format)

Now, the weird thing is, If I run this program as "Run as Administrator" I don't get this error, and it works as intended.

The reason I don't want it to be "Run as Administrator" is that I need to it run on Computer Startup without using external VBScripts and other stuff like that.

How do I resolve this?

Kevin Jensen Petersen
  • 423
  • 2
  • 22
  • 43

0 Answers0