简体   繁体   English

CreateProcessAsUser()未显示正在运行的进程[C#]的CreateWindow

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

My system has 2 accounts (USER and ADMIN) and a service (Service.exe) running under LocalSystem. 我的系统有2个帐户(USER和ADMIN)和在LocalSystem下运行的服务(Service.exe)。 The user logs into the USER account, the LocalService can then launch a process (CreateProcessAsUser(...)) as the ADMIN user. 用户登录到USER帐户,然后LocalService可以以ADMIN用户身份启动进程(CreateProcessAsUser(...))。

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... 服务运行的过程(Tool.exe)是一个旧版C ++应用程序,该应用程序执行作业并通过使用CreateWindow(...)向用户显示信息,但是由服务启动它时,窗口不会显示...

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) 当服务创建该过程时,我首先加载ADMIN用户的配置文件和环境,以便使用正确的上下文...(但仍希望Window将显示给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? 现在,最初我以为这会在ADMIN运行该过程时引起问题,为什么在USER桌面上会输出CreateWindow(...),所以我尝试了一个简单的命令行test.exe应用程序,并以ADMIN的身份启动时出现命令提示符窗口-为什么在CreateWindow(...)无法正确显示的情况下可以正常工作?

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? 关于如何使状态(使用Tool.exe中的CreateWindow)在ADMIN下运行以显示在USER登录会话中的任何线索?

Can I use the ENVIRONMENT somehow, I tried the following thinking it might work but didn't: 我可以以某种方式使用环境吗,我尝试了以下方法,但它可能行得通,但没有成功:

startInfo.lpDesktop = @"WinSta0\Default";
startInfo.dwFlags = STARTF_USESHOWWINDOW;
startInfo.wShowWindow = SW_SHOW;

The Window is created as follows (in Tool.exe): 窗口创建如下(在Tool.exe中):

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)? lpDesktop是否错误(不确定该如何工作)?

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... 我知道这听起来有多疯狂-我只希望不必以USER身份启动另一个ToolDisplay.exe,当Tool.exe自行处理所有内容时,它以ADMIN身份与Tool.exe进行通信-因此,请检查是否没有解决这个问题的好方法...

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(...). 我的系统有2个帐户(USER和ADMIN),用户始终以USER身份登录,但在某些特定时间,在ADMIN帐户下启动了进程(Tool.exe)(通过LocalSystem Service使用CreateProcessAsUser(...)) ,几乎所有的东西都可以正常工作,除了该过程(Tool.exe)应该使用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? 当Tool.exe运行(作为ADMIN)并且用户以USER身份登录时,该窗口不显示(很明显)...有没有办法向登录的用户显示在ADMIN下运行的Tool.exe窗口,以USER身份开启?

Any help would be much appreciated... Thanks, 任何帮助将不胜感激...谢谢,

Just in case you want a window / GUI spawned by a service to be visible, Go to-> run prompt -> services.msc -> go to your service's property, check "Allow service to interact with desktop". 万一您希望看到由服务生成的窗口/ GUI,请转到->运行提示-> services.msc->转到服务的属性,选中“允许服务与桌面交互”。 Then restart your service. 然后重新启动服务。

Note that in Vista, the prompt will NOT be visible even after above. 请注意,在Vista中,即使经过以上操作,该提示也将不可见。 This is due to sessions issue. 这是由于会话问题。 However there is a service which helps support prompts from services (I think it is Interactive Services Detection service). 但是,有一项服务可以帮助支持来自服务的提示(我认为这是“交互式服务检测”服务)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM