C# 使用c将屏幕截图捕获为服务器上的计划任务#
我已经编写了以下c#代码,并希望将其作为服务器上的计划任务运行。然而,由于这部分代码,我得到了异常。我假设这个错误与没有屏幕这一事实有关。是否有人找到了将屏幕捕获为计划任务且未连接到远程系统的方法C# 使用c将屏幕截图捕获为服务器上的计划任务#,c#,screenshot,rdp,C#,Screenshot,Rdp,我已经编写了以下c#代码,并希望将其作为服务器上的计划任务运行。然而,由于这部分代码,我得到了异常。我假设这个错误与没有屏幕这一事实有关。是否有人找到了将屏幕捕获为计划任务且未连接到远程系统的方法 Bitmap bt; // a browser is running for which screen shot needs to be taken. bt = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Scr
Bitmap bt;
// a browser is running for which screen shot needs to be taken.
bt = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb);//use 24bbp for capture image as AForge supports only 24bpp.
Graphics screenShot = Graphics.FromImage(bt);
screenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bt.Save(@"C:\folder\test.png", ImageFormat.Png);
由于我在服务器上运行它,它没有连接任何物理监视器,因此我必须远程连接到服务器。当我手动运行它时,没有错误。但是,当我计划它并从机器注销时,它会给我以下消息
Application: ConsoleAppCaptureScreenshot.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ComponentModel.Win32Exception
Stack:
at System.Drawing.Graphics.CopyFromScreen(Int32, Int32, Int32, Int32, System.Drawing.Size, System.Drawing.CopyPixelOperation)
at ConsoleAppCaptureScreenshot.Program.Main(System.String[])
例外情况是什么,您还提到rdp等?不要读任何关于那的东西?你是说没有附加物理屏幕?Screen对象未引用实际屏幕:)