TL;DR I am writing a remote desktop application and having trouble with logging the user in and capturing the default desktop using DXGI; currently, I am only able to capture the screensaver desktop.
Hello! I'm writing a C application that uses DXGI to capture the desktop of a remote computer (like TeamViewer or VNC). Following these posts (1) (2) and TightVNC's source code, I wrote the following code which opens a Windows Station and desktop and gives the thread access to the desktop:
BOOL logon = LogonUser("username",
NULL,
"password",
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hToken);
hwinsta = OpenWindowStation("winsta0",
FALSE,
GENERIC_ALL);
BOOL process = SetProcessWindowStation(hwinsta);
HDESK hdesk = OpenInputDesktop(0,
FALSE,
GENERIC_ALL);
SetThreadDesktop(hdesk);
After this, I call DXGI (as documented [here]), but the output that's captured is the Windows screensaver desktop (despite me successfully calling the LogonUser()
function). I tried manually setting the desktop to the default desktop with
HDESK hdesk = OpenDesktop("default",
0,
FALSE,
GENERIC_ALL);
but when I do so, the DuplicateOutput()
function fails with 0x80070005, which is the ACCESS_DENIED error.
Does anyone have an idea of what I could be doing differently to log the user on and switch past the screensaver/winlogon desktops to the default desktop?
Thank you!
User contributions licensed under CC BY-SA 3.0