How to CreateProcessAsUser and make it a foreground window?

3k views Asked by At

I'm trying to start an UI using CreateProcessAsUser but the window doesn't come as the foreground Window.

I wouldn't mind if it was a normal window, but this window triggers the UAC prompt and it isn't displayed in foreground neither.

1

There are 1 answers

1
Billy ONeal On BEST ANSWER

From your description, it sounds as if you are trying to launch the other process in elevated mode. If that's what you're trying to do, you cannot set it to the foreground window. In fact, non-elevated processes aren't allowed to touch elevated processes in any way/shape/form.

The created process has to be responsible for actually making its own window the foreground window. Try playing with the STARTUPINFO structure you pass to CreateProcessAsUser, setting the STARTF_USESHOWWINDOW flag, and specifying a value of SW_SHOWNORMAL. If that doesn't work, there's no real workaround other than elevating part of yourself first, such as creating an elevated COM component.

If that's not what you're trying to do, and you simply want to move the child process' window to the foreground, then you have to enumerate windows owned by the child process and then call SetForegroundWindow on one of them.