AssignProcessToJobObject 失败并显示“访问被拒绝” 在调试器下运行时出错
您执行AssignProcessToJobObject
,但仅当您在调试器中运行时,它会因“访问被拒绝”而失败。 为什么是这样?
You do AssignProcessToJobObject
and it fails with "access denied" but only when you are running in the debugger. Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎经常困扰着我,虽然很好,但 1800INFORMATION 的帖子似乎没有包含一些看起来有帮助的原因和修复方法,因此似乎值得发布我看到这种情况发生的原因的摘要。
从 CMD.EXE、资源管理器运行时,可能会因不同原因发生
和视觉工作室。 尝试从以下位置运行失败的可执行文件
相应的地方可以帮助找出问题的原因。 你
尽管从 VS 失败,但应用程序可能只能从 CMD.EXE 找到
和 Explorer.exe
app.manifest 中指示 Win7 兼容性的元素
文件。 这似乎解决了从资源管理器运行时的问题。 到
添加清单,右键单击项目,点击添加,然后查找
“应用程序清单文件”。
This seems to bite me quite often, and while good, 1800INFORMATION's post doesn't seem to include a number of reasons and fixes that seem helpful, so it seem worthwhile to post a summary of why I've seen this happen.
can occur for different reasons when running from CMD.EXE, Explorer,
and Visual Studio. Trying to run the failing executable from the
respective places can help identify the cause of the problem. You
app may just work find from CMD.EXE in spite of failing from V.S.
and Explorer.exe
element indicating Win7 compatibility from the app.manifest
file. This seems to fix the problem when running from Explorer. To
add a manifest, right click on the project, hit Add, and find
'Application Manifest File'.
这个问题让我困惑了大约30分钟。
首先,您可能需要在应用程序中嵌入 UAC 清单(
其次(这是我陷入困境的一点),当您在调试器下运行应用程序时,它会在作业对象中创建您的进程。 您的子进程需要能够脱离它,然后才能将其分配给您的工作。 所以(废话),您需要在
CreateProcess
的标志中指定CREATE_BREAKAWAY_FROM_JOB
)。如果您没有在调试器下运行,或者您的父进程在作业中,则不会发生这种情况。
This one puzzled me for for about 30 minutes.
First off, you probably need a UAC manifest embedded in your app (as suggested here). Something like this:
Secondly (and this is the bit I got stuck on), when you are running your app under the debugger, it creates your process in a job object. Which your child process needs to be able to breakaway from before you can assign it to your job. So (duh), you need to specify
CREATE_BREAKAWAY_FROM_JOB
in the flags forCreateProcess
).If you weren't running under the debugger, or your parent process were in the job, this wouldn't have happened.