Remote Deskotp Mouse Interactions are not working when TaskManager is in Foreground
Edition: Windows Server 2016 Datacenter
OS build: 14393.4704
First of all, we have launched a remote desktop (wfreerdp.exe) as a user with elevated privileges.
Next, we are trying to send mouse inputs to the remote desktop using the SendInput function (winuser.h) from another process launched by the same user (The process is launched from python using the CreateProcessAsUser API with the token we got from WTSQueryUserToken API). And, this process is not elevated.
ut = win32ts.WTSQueryUserToken(int(sessionid)) procHandles = win32process.CreateProcessAsUser(ut, *procArgs)
Initially, it works well in interacting with the applications like Notepad, File Explorer, etc. As soon as we open TaskManager and bring it to the foreground, interactions will stop working until the TaskManager is taken out of the foreground. After that, interactions work again as usual.
Surprisingly, the SendInput function is not giving any error codes when interactions are not working.
Developers often make the mistake of thinking that SendInput is an easy solution. And then they have problems. SendInput requires that the receiving program has the focus. You can add code to first activate the other program.
A more reliable solution is to add text or update the text in a control, or do whatever you need to do to the relevant control(s). In other words, do something that sends a WM_SETTEXT message, not WM_CHAR message(s).
Also, we tried launching the second process with elevated privileges and sending mouse inputs using the SendInput function (winuser.h). Since both wfreerdp.exe and the second process are launched with elevated privileges, we expected it to work.
But, interactions are not all working with any application including Notepad, File Explorer, etc. The complete desktop feels frozen. This time the SendInput function (winuser.h) gives error code 5, which means ERROR_ACCESS_DENIED.
We can't understand why that is so.
From the documentation for the SendInput function -
"This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level."
"This function fails when it is blocked by UIPI. Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking."
Haven't heard from you for a while. Hope you've been well! Have you got any updates about this issue?
Sign in to comment