CreateProcessAsUser() not showing CreateWindow of running Process [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
My system has 2 accounts (USER and ADMIN) and a service (Service.exe) running under LocalSystem.
The user logs into the USER account, the LocalService can then launch a process (CreateProcessAsUser(...)) as the ADMIN user.

The process the Service runs (Tool.exe) is a legacy C++ application that performs a job and also displays information to the user by using CreateWindow(...), but when launching it by the Service the Window does not show...

When the process is created by the Service I first load the Profile & Environment of the ADMIN user so that the correct context is used ...
(was still hoping the Window would display to USER)


Now, initialy I thought this would cause a problem as ADMIN is running the process so why would the CreateWindow(...) output in the USER desktop, so I tried with a simple command-line test.exe app and when launched as ADMIN the Command Prompt window appeared - so why does that work fine where-as the CreateWindow(...) doesn't display correctly?

Any clues on how I can get the STATUS (using CreateWindow in Tool.exe) running under ADMIN to show in the USER logged-on session?

Can I use the ENVIRONMENT somehow, I tried the following thinking it might work but didn't:
Code:
    startInfo.lpDesktop = @"WinSta0\Default";
    startInfo.dwFlags = STARTF_USESHOWWINDOW;
    startInfo.wShowWindow = SW_SHOW;

The Window is created as follows (in Tool.exe):
Code:
    HWND hwnd = CreateWindow
    (
        "Tool", 
        "Tool WINDOW",
        WS_POPUP | WS_VISIBLE,
        0,0,uWidth,uHeight,
        NULL, 
        NULL, 
        hInstance, 
        Text
    );

Is the lpDesktop wrong (not exactly sure how this works)?


I know how crazy this sounds - I just would rather not have to launch another ToolDisplay.exe as USER which communicates with Tool.exe as ADMIN as a display when the Tool.exe used to handle everything on its own - so checking to see if there isn't some nice way to handle this...

Any help would be much appreciated...
Thanks,
 
Simplified Question:
My system has 2 accounts (USER and ADMIN), the user is always logged on as USER but at some specific times a process (Tool.exe) is launched under the ADMIN account (by a LocalSystem Service using CreateProcessAsUser(...)), almost everything works fine except for the fact that the process (Tool.exe) is supposed to display status to the user using CreateWindow(...).

When Tool.exe is running (as ADMIN) and the user is logged-on as USER the window is not shown (obviously)...
Is there a way to show the window of Tool.exe running under ADMIN to the user logged-on as USER?

Any help would be much appreciated...
Thanks,
 
As a rule services (an anything they launch) do not have access to the logged in users' desktop (for starters there could be multiple users logged in - which desktop should the application display it's information on?).

Typically you would create an application which would communicate with the service and run the application from the logged in user - this way the application can display things.

It might work if you allow the service to interact with the desktop but I'm not sure if that would also mean any applications the service launches would also be able to interact with the desktop.
 
Back
Top