[英]How to run a process with ShellExecuteEx as as a child that closes after parent exit?
I need to spawn a process which need to invoke UAC. 我需要产生一个需要调用UAC的进程。 I have read this post: How can I run a child process that requires elevation and wait?
我已经阅读了这篇文章: 如何运行需要提升并等待的子进程? .
。
Unfortunatelly I can't run a process as a real child. 不幸的是,我不能像一个真正的孩子那样运行流程。 The new process run as a separate and continue to run even after spawner close.
新进程将作为单独的进程运行,即使在生成器关闭后仍继续运行。 But I need it to close automatically when parent exits (normal exit or by crash or any other reason).
但是我需要它在父母退出时自动关闭(正常退出或由于崩溃或任何其他原因)。
One of the solution that were provided is to use jobs for that. 提供的解决方案之一就是为此使用作业。 Unfortunately I can't assign a process created with
ShellExecuteEx
to a job. 不幸的是,我无法将用
ShellExecuteEx
创建的进程分配给作业。 It returns me an error ERROR_ACCESS_DENIED
. 它返回错误
ERROR_ACCESS_DENIED
。 To handle this I have to pass CREATE_BREAKAWAY_FROM_JOB
to CreateProcess
. 为了解决这个问题,我必须将
CREATE_BREAKAWAY_FROM_JOB
传递给CreateProcess
。 And this is the closed circle. 这是一个封闭的圈子。 I have to use
ShellExecuteEx
but not CreateProcess
. 我必须使用
ShellExecuteEx
而不是CreateProcess
。
You have the use the shell verb runas
to force elevation. 您可以使用外壳动词
runas
强制提升。 Which rules out CreateProcess
. 哪个排除
CreateProcess
。 So you can do the following: 因此,您可以执行以下操作:
ShellExecuteEx
to create the child process. ShellExecuteEx
创建子进程。 ShellExecuteEx
to return a process handle for the child. ShellExecuteEx
返回该子项的进程句柄。 If you want to use jobs to tie the processes lives together then you need to include the requiresAdministrator
manifest option of the child. 如果要使用作业将流程的生命联系在一起,则需要包括子项的
requiresAdministrator
清单选项。 That way you can use CreateProcess
and specify the process creation flags as you desire. 这样,您可以使用
CreateProcess
并根据需要指定进程创建标志。
Now, you may wish not to have the child process manifested that way. 现在,您可能不希望子进程以这种方式表现出来。 If so then you can still get the job done with a call to
CreateProcess
. 如果是这样,那么您仍然可以通过调用
CreateProcess
来完成工作。 You need three processes: 您需要三个过程:
CreateProcess
and placed in same job. CreateProcess
并放置在同一工作中。 The point here is that there are two ways to force elevation. 这里的要点是有两种方法可以强制抬高。 Statically at compile time with a manifest.
带有清单的静态编译时。 That allows you to use
CreateProcess
. 这样就可以使用
CreateProcess
。 Or dynamically with the runas
shell verb. 或与
runas
shell动词一起动态使用。 That forces ShellExecuteEx
. 这迫使
ShellExecuteEx
。 You state that you are pushed to CreateProcess
, and so that means the use of a manifest to force elevation. 您声明已被推送到
CreateProcess
,因此这意味着使用清单来强制提升。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.