屏幕截图安全桌面



我正在使用屏幕共享项目。我正在使用下面捕获桌面屏幕 function.it 工作正常。但是,每当安全桌面提示输入 elevation.it 时,都会返回黑色/空图像。

但是当我从本地安全策略关闭安全桌面时。它工作正常。

有没有办法在不禁用本地安全策略的情况下捕获安全桌面。

static Bitmap CaptureDesktop()
{
SIZE size;
Bitmap printscreen = null;
size.cx = Win32Stuff.GetSystemMetrics
(Win32Stuff.SM_CXSCREEN);
size.cy = Win32Stuff.GetSystemMetrics
(Win32Stuff.SM_CYSCREEN);
int width = size.cx; int height = size.cy;
IntPtr hWnd = Win32Stuff.GetDesktopWindow();
IntPtr hDC = Win32Stuff.GetDC(hWnd);
if (hDC != IntPtr.Zero)
{
IntPtr hMemDC = GDIStuff.CreateCompatibleDC(hDC);
if (hMemDC != IntPtr.Zero)
{
IntPtr m_HBitmap = GDIStuff.CreateCompatibleBitmap(hDC, width, height);
if (m_HBitmap != IntPtr.Zero)
{
IntPtr hOld = (IntPtr)GDIStuff.SelectObject(hMemDC, m_HBitmap);
GDIStuff.BitBlt(hMemDC, 0, 0, width, height, hDC, 0, 0, GDIStuff.SRCCOPY);
GDIStuff.SelectObject(hMemDC, hOld);
GDIStuff.DeleteDC(hMemDC);
printscreen = System.Drawing.Image.FromHbitmap(m_HBitmap);
GDIStuff.DeleteObject(m_HBitmap);
}
}
}
Win32Stuff.ReleaseDC(hWnd, hDC);
return printscreen;
}

编辑

  1. Exe 安装在安全位置
  2. Exe 已进行数字签名

为了获取安全桌面的屏幕内容,您的应用程序需要满足一些特殊条件:

  • 它必须在系统帐户下运行,而不是在登录的用户帐户下运行
  • 它必须在 Winlogon 桌面上运行,而不是在用户桌面上运行
  • 它应该作为服务运行

为了测试它,你可以使用SysInternals PsExec工具在该模式下运行你的应用程序:

PsExec /h /x /d /s "path_toyour_application.exe"

/x/s开关很重要:它们在系统帐户和Winlogon桌面上运行该过程。

如果要避免使用第三方工具,则需要创建自己的Windows服务,该服务将执行安全桌面的屏幕截图。

没有可用的PsExec源代码,但您可以查看PAExec工具的源代码 - 它是一个开源替代方案。

最新更新