我正在处理屏幕共享项目。我正在使用以下功能捕获桌面屏幕。它工作正常。但每当安全桌面提示提升 https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/user-account-control-switch-to-the-secure-desktop-when-prompting-for-elevation.它返回黑色/空图像。
但是当我关闭安全桌面 https://www.thewindowsclub.com/how-to-turn-off-the-secure-desktop-in-windows-7来自本地安全策略。它工作正常。
有没有办法在不禁用本地安全策略的情况下捕获安全桌面。
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;
}
Edit:
- Exe 安装在安全位置
- exe经过数字签名
为了获取安全桌面的屏幕内容,您的应用程序需要满足一些特殊条件:
- 它必须在 SYSTEM 帐户下运行,而不是在登录用户帐户下运行
- 它必须在 Winlogon 桌面上运行,而不是在用户桌面上
- 它应该作为服务运行
要测试它,您可以例如使用SysInternals PsExec 工具 https://learn.microsoft.com/en-us/sysinternals/downloads/psexec以该模式运行您的应用程序:
PsExec /h /x /d /s "path_to\your_application.exe"
The /x
and /s
开关很重要:它们在 SYSTEM 帐户下和 Winlogon 桌面上运行该进程。
如果您想避免使用第三方工具,则需要创建自己的 Windows 服务来执行安全桌面的屏幕截图。
没有源代码PsExec
可用,但你可以看看PAExec
tool's 源代码 https://github.com/poweradminllc/PAExec- 这是一个开源替代方案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)