gpt4 book ai didi

CreateProcessWithLogonW 和 AssignProcessToJobObject

转载 作者:可可西里 更新时间:2023-11-01 10:02:03 29 4
gpt4 key购买 nike

我有一个 Windows 服务(在 WinXP SP2 下),在 LocalSystem 帐户下运行,它使用 CreateProcessWithLogonW 启动进程。为了清理子进程,我尝试使用作业对象和 TerminateJobObject。

MSDN 声明作业句柄必须具有 JOB_OBJECT_ASSIGN_PROCESS 访问权限,因为它是通过 CreateJobObject 创建的。进程句柄必须具有 PROCESS_SET_QUOTA 和 PROCESS_TERMINATE 权限。我认为它有它们,因为 TerminateProcess 和 SetProcessWorkingSetSize 都没有错误地返回。

但是,AssignProcessToJobObject 失败并显示错误号 5(访问被拒绝)。如果我将 CreateProcessWithLogonW 替换为简单的 CreateProcess,则一切正常。

我是不是遗漏了什么或者我想做的事情是不可能的?

编辑:似乎在使用 CreateProcessWithLogonW 时实际创建进程的 svchost.exe 似乎已经将进程分配给匿名作业。此函数忽略 CREATE_CREAKAWAY_FROM_JOB 标志。所以真正的问题是:有没有办法阻止 svnhost 将进程分配给作业?

最佳答案

来自 Jeff Lawson在 MSDN 上:

Interactions with Win32 Job Objects

CreateProcessWithLogonW executes thenew process as a child of theSecondary Logon service, which has theoutcome of making the process escapeany Job Object membership/restrictionseven if the Job Object did not allowbreakaway.

Furthermore, the SecondaryLogon service automatically createsits own new Job Object and assigns thenew process into it. As such, it isnot possible for the caller toexplicitly assign the new process toany other Job Object (since a processmay only be assigned to one JobObject, and can never be removed froma Job Object once it has been assignedto one).

是否每个新进程都需要不同的登录?否则,您可以使用新登录创建一个进程,并使用 CreateProcess 生成新进程,然后将其与作业对象相关联。

关于CreateProcessWithLogonW 和 AssignProcessToJobObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1287620/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com