I'm currently using this code to restore a minimized window, and it works perfectly when I try to restore a window that runs under my own user account.
ShowWindow(wHandle, SW_RESTORE);
The problem arises when I try to restore a window that runs under the SYSTEM account. I found out that ShowWindow()
always returns a false value to me. Also, in my manifest, I have tried setting it to both "Requires Administrator" and "As Invoker", but it still yields the same result.
Is there another function that works similarly to ShowWindow()
and is able to restore a window that is running under the SYSTEM account?
You can create a thread with "local system" privileges in the user application. Then execute your ShowWindow
in the thread.
Some steps:
OpenProcessToken
and DuplicateTokenEx
to create a
Local System tokenSetTokenInformation
to change the token session ID to
match the program'sDuplicateHandle
to create handle to the tokenSetThreadToken
using the received handleRefer: Run process as Local System
For the @fpiette's comment, Interacting with a User from a Service Indirectly shows more details.