我正在使用屏幕共享项目.我正在使用以下功能捕获桌面屏幕.它工作正常.但是每当安全桌面提示提升时,都会返回黑/空图像.
但是,当我从本地安全策略关闭安全桌面时.它工作正常.
有没有办法捕获安全桌面而不禁用本地安全策略.
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;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
为了获取Secure Desktop的屏幕内容,您的应用程序需要满足一些特殊条件:
要测试它,您可以使用SysInternals PsExec工具以该模式运行您的应用程序:
PsExec /h /x /d /s "path_to\your_application.exe"
Run Code Online (Sandbox Code Playgroud)
在/x和/s开关是很重要的:它们运行在系统帐户和Winlogon桌面上的进程.
如果要避免使用第三方工具,则需要创建自己的Windows服务,该服务将执行Secure Desktop的屏幕截图.
没有PsExec可用的源代码,但您可以查看该PAExec工具的源代码 - 它是一个开源替代品.