我正在与屏幕共享项目合作。我使用下面的函数捕获桌面屏幕,它运行良好。但是每当安全桌面提示提升权限时,它会返回黑色/空白图像。
但是当我从本地安全策略关闭安全桌面时,它可以正常工作。
有没有办法在不禁用本地安全策略的情况下捕获安全桌面?
但是当我从本地安全策略关闭安全桌面时,它可以正常工作。
有没有办法在不禁用本地安全策略的情况下捕获安全桌面?
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;
}
编辑:
- 应将Exe安装在安全位置
- Exe应进行数字签名