我有一个在客户端计算机上运行的 Windows 服务。我需要捕获客户端的屏幕并通过远程处理将其发送到服务器。当我运行exe文件时,它可以捕获屏幕并将其发送到服务器。但是当我将其作为服务运行时,它会记录以下错误:
“句柄无效。”
该服务的“与桌面交互”复选框已选中。我用于截图的代码是:
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;
可能是什么原因以及如何解决此问题?
最佳答案
服务在 session 0 中运行(从 Vista 开始),而应用程序的其余部分则不然。
使用(例如)Run 登录后,您需要在用户 session 中运行屏幕捕获应用程序。注册表项。
关于c# - 无法捕捉屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1595801/