- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 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/
我有一个 Windows 服务(在 WinXP SP2 下),在 LocalSystem 帐户下运行,它使用 CreateProcessWithLogonW 启动进程。为了清理子进程,我尝试使用作业对
我有以下代码: #include #include #include #pragma comment ( lib, "shlwapi.lib" ) int __cdecl wmain( int
您执行 AssignProcessToJobObject 并失败并显示“拒绝访问”,但仅当您在调试器中运行时。这是为什么呢? 最佳答案 这个让我困惑了大约 30 分钟。 首先,您可能需要在应用中嵌入
我是一名优秀的程序员,十分优秀!