简体   繁体   English

截屏:Windows Server中窗体中具有Web浏览器控件的WinForms应用程序

[英]Take screenshot: WinForms application with Web Browser Control in Form in Windows Server

I am using the following code to capture a Form screenshot: 我正在使用以下代码来捕获Form屏幕截图:

            this.TopMost = true;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            this.Activate();
            Application.DoEvents();



            Bitmap screenShotBMP = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP);
            screenShotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            screenShotBMP.Save(imagePath, ImageFormat.Gif);
            screenShotGraphics.Dispose();
            screenShotBMP.Dispose();


            this.TopMost = false;
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.WindowState = FormWindowState.Minimized;

When I am logged in to the server, it works fine (I can see the screenshots generated) But when its locked, the line: 当我登录到服务器时,它可以正常工作(我可以看到生成的屏幕截图),但是当它锁定时,该行:

        screenShotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

Gives the error "Handle is invalid". 给出错误“句柄无效”。

I came to know that its because there is no desktop when no one is logged in. So can anyone let me know any alternatives? 我知道这是因为没有人登录时就没有桌面。那么有人可以让我知道其他选择吗?

What I have is a WinForms application, scheduled to run after every 5 mins and when it runs, I have to take a screenshot of the Form . 我所拥有的是一个WinForms应用程序,该应用程序计划每5分钟运行一次,当它运行时,我必须对Form进行截图。

Please let me know a soluion. 请让我知道一个解决方案。

This is not going to be possible. 这是不可能的。 When a workstation is locked, Winlogon switches to the secure desktop. 工作站锁定后,Winlogon切换到安全桌面。 In this case, like you said, there is no desktop of which to take a picture. 在这种情况下,就像您所说的,没有台式机可以拍照。

Not even administrators have access rights to the secure desktop, so you couldn't take a picture of it , even if you wanted to. 甚至没有管理员有权访问安全桌面,所以你不能把的照片,即使你想。 The only possible way to work around the security restrictions you're running afoul of here is to rewrite the application as a service so that you would gain access rights to the secure desktop, but then you would run into another set of security restrictions: namely, that services aren't allowed to interact with the user in any way and therefore do not have a "desktop". 解决此处遇到的安全性限制的唯一可能方法是将应用程序重写为服务,以便获得对安全桌面的访问权限,但是随后会遇到另一组安全性限制:即,则该服务不允许以任何方式与用户互动,因此没有“桌面”。

It's unclear what you even expect to happen in this scenario. 目前还不清楚是什么,你甚至希望在这种情况下发生的。 If there's no desktop to take a picture of, what would you want it to take a picture of? 如果没有台式机可以拍照,那么您希望它拍照吗?

The bottom line is that Windows is a multi-user operating system and has been for decades now. 最重要的是,Windows是多用户操作系统,并且已经使用了数十年。 You have to give up on this 16-bit conceptual model where there is only one "desktop" and everyone has full access privileges to everything. 您必须放弃只有一个“桌面”且每个人都拥有对所有内容的完全访问权限的16位概念模型。

There are other, better ways of monitoring what is happening on a workstation than taking periodic screenshots… Ways that actually work even. 除了定期捕获屏幕快照外,还有其他更好的方法来监视工作站上发生的事情……甚至可以真正起作用。 I can't make general suggestions because it depends on what exactly you're trying to monitor. 我无法提出一般建议,因为这取决于您要监视的内容。

我刚刚测试了PrintWindow api,它在锁定桌面的情况下可以正常工作: C#PrintWindow返回黑色图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM