CreateProcessWithLogonW和AssignProcessToJobObject [英] CreateProcessWithLogonW and AssignProcessToJobObject

查看:187
本文介绍了CreateProcessWithLogonW和AssignProcessToJobObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Windows service (under WinXP SP2), running under the LocalSystem account, that launches processes using CreateProcessWithLogonW. In order to clean up child processes, I'm trying to use a job object and TerminateJobObject.

MSDN指出,工作手柄必须JOB_OBJECT_ASSIGN_PROCESS访问权,由它,因为它是通过创建CreateJobObject。进程句柄必须有PROCESS_SET_QUOTA和PROCESS_TERMINATE权利。我认为这是他们自TerminateProcess和SetProcessWorkingSetSize都没有返回错误。

MSDN states that the job handle must have JOB_OBJECT_ASSIGN_PROCESS access right, which it has since it's created via CreateJobObject. The process handle must have PROCESS_SET_QUOTA and PROCESS_TERMINATE rights. I think it has them since TerminateProcess and SetProcessWorkingSetSize both return with no error.

不过,AssignProcessToJobObject失败,错误号5(拒绝访问)。如果我用一个简单的CreateProcess代替CreateProcessWithLogonW一切工作正常。

Though, AssignProcessToJobObject fails with errno 5 (Access denied). Everything works fine if I replace CreateProcessWithLogonW with a simple CreateProcess.

我缺少的东西或者是什么,我试图做不可能的?

Am I missing something or is what I'm trying to do impossible ?

编辑:看来,svchost.exe的,它实际上创建时使用CreateProcessWithLogonW的过程中,已分配的过程中匿名的工作。该CREATE_CREAKAWAY_FROM_JOB标志通过这个功能忽略。所以真正的问题是:有没有从分配过程中的作业的方式prevent svnhost

It seems that svchost.exe, which actually creates the process when CreateProcessWithLogonW is used, already assigns the process to an anonymous job. The CREATE_CREAKAWAY_FROM_JOB flag is ignored by this function. So the real question is: is there a way to prevent svnhost from assigning the process to a job ?

推荐答案

从的杰夫·劳森在MSDN上的:

的Win32工作对象的交互

CreateProcessWithLogonW执行
  新过程的一个子
  Secondary Logon服务,它具有
  制作过程中逃逸的结果
  任何招聘对象会员/限制
  即使招聘对象不容许
  远走他乡。

CreateProcessWithLogonW executes the new process as a child of the Secondary Logon service, which has the outcome of making the process escape any Job Object membership/restrictions even if the Job Object did not allow breakaway.

此外,二次
  登录服务会自动创建
  自己的新工作对象和分配
  新工艺进去。因此,它是
  不可能呼叫者
  明确指定的新工艺
  任何其他工作对象(因为过程
  只能被分配到一个职位
  对象,永远不能从中删除
  一个作业对象一旦被分配
  至一个)。

Furthermore, the Secondary Logon service automatically creates its own new Job Object and assigns the new process into it. As such, it is not possible for the caller to explicitly assign the new process to any other Job Object (since a process may only be assigned to one Job Object, and can never be removed from a Job Object once it has been assigned to one).

每一个新的过程中需要不同的登录?否则,你可以用新的登录创建一个单一的过程,并把它使用然后可以与工作对象相关的CreateProcess产生新的进程。

Does each new process need a different logon? Otherwise, you could create a single process with the new logon and have it spawn new process using CreateProcess that could then be associated with a Job Object.

这篇关于CreateProcessWithLogonW和AssignProcessToJobObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆