用C#和远程桌面问题的屏幕截图 [英] Screen capture with C# and Remote Desktop problems

查看:534
本文介绍了用C#和远程桌面问题的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有抓住MS Word文档几次的截图一个C急剧控制台应用程序。它的伟大工程,但是当我把这个应用程序的远程Windows XP机器上正常工作,而我也就是我远程连接我的远程桌面是可见的,但如果我跑我的应用程序,并留下远程桌面(最小化,甚至不是日志关我想做的事情)所花费的截图都是空白!

I have a C sharp console application that captures a screenshot of a MS Word document several times. It works great, but when I place this application on a remote windows XP machine it works fine whilst I am remoted in i.e. my remote desktop is visible but if I run my app and leave remote desktop (minimize it, not even log off which I want to do) the screenshots it takes are blank!

截图应用程序正在被运行作为SYSTEM用户的服务运行。

The Screenshot app is being run by a service that runs as SYSTEM user.

我怎么能保证GUI活着的窗口,即使没有连接的用户?

How can I keep the GUI alive for windows even when there are no users connected?

下面是我的代码使用方法:

Here is the code I use:

public Image CaptureWindow(IntPtr handle)
{
    // get te hDC of the target window
    IntPtr hdcSrc = User32.GetWindowDC(handle);
    // get the size
    User32.RECT windowRect = new User32.RECT();
    User32.GetWindowRect(handle, ref windowRect);
    int width = windowRect.right - windowRect.left;
    int height = windowRect.bottom - windowRect.top;
    // create a device context we can copy to
    IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
    // create a bitmap we can copy it to,
    // using GetDeviceCaps to get the width/height
    IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
    // select the bitmap object
    IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
    // bitblt over
    GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
    // restore selection
    GDI32.SelectObject(hdcDest, hOld);
    // clean up 
    GDI32.DeleteDC(hdcDest);
    User32.ReleaseDC(handle, hdcSrc);

    // get a .NET image object for it
    Image img = Image.FromHbitmap(hBitmap);
    // free up the Bitmap object
    GDI32.DeleteObject(hBitmap);

    return img;
}



更新



我目前正在在使用PrintWindow的这是因为它设法捕捉窗框已经来到最接近的唯一的事(即最小化,最大化和关闭按钮),但内部是黑色的。

Update

I am currently making use of PrintWindow which is the only thing that has come the closest as it manages to capture the window frame (i.e the minimise, maximise and close buttons) but the inner part is black.

虽然尚未完全工作,其向我证明它可以从一个窗口句柄创建一个图像,而该应用程序甚至没有对用户可见。

Although it hasn't fully worked, its proved to me that it is possible to create an image from a window handle whilst the application isn't even visible to a user.

推荐答案

前一段时间我们在做类似的事情,我们发现,当RDC最小化,远程桌面会话不会重绘或接受键或鼠标事件。一切工作正常,直到我们最小化RDC屏幕。一位同事发现,这是出于性能方面的实现。

Some time ago we were doing something similar, and we found that when RDC is minimized, the remote desktop session is not redrawn or accept keys or mouse events. Everything was working fine until we minimized the RDC screen. A colleague found out that this is done for performance reasons.

若干天前,我偶然发现了这一点,但我还没有去尝试的机会。如果你试图和它的作品,请让我知道:)

Some days ago I stumbled upon this, but I haven't had the chance to try it. If you try and it works, please let me know :)

同当RDC最小远程桌面交互

关于您的意见:我觉得这是另一种问题...我知道你需要您的应用程序,即使没有用户登录到机器的工作。我实现了允许与桌面交互,例如服务,启动应用程序和自动化。即使没有人在本机登录,您仍然可以操作的用户界面,例如,与UI自动化库(或你的代码,我假设)。

Regarding your comments: I think this is another kind of issue... I understand that you need your application to work even if no one is logged into the machine. I've implemented services that are allowed to interact with the desktop, for example, to launch an application and automate it. Even no one is logged in the machine, you can still manipulate the UI, for example, with an UI automation library (or your code, I assume).

启动后机器,当我的服务和应用程序的自动运行一切正常。后来,被自动会出现谁登录的第一人的桌面上的UI(我是计算机管理员,我不知道什么时候有人用更少的权限登录会发生什么)。

After starting the machine, when my service and automated application are running everything works fine. Later on, the UI being automated will appear on the desktop of the first person who logs in (I was a machine administrator, I don't know what will happen when somebody with less privileges logs in).

我不知道,如果在第一次登录是通过RDC做会发生什么。也许你可以尝试改变这些设置RDC ID这会影响您的应用程序的行为。另一种选择是:

I don't know what will happen if the first login is done through RDC. Maybe you could try changing those RDC settings id this affects the behavior of your application. Another option is:


  1. 禁用RDC,并与指定的帐户将Windows配置为自动登录

  2. 连接到本机使用其它远程桌面应用程序(例如TightVNC的)

这是否帮助?

这篇关于用C#和远程桌面问题的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆