AssignProcessToJobObject 失败并显示“访问被拒绝” 在调试器下运行时出错

发布于 2024-07-04 11:25:28 字数 84 浏览 6 评论 0原文

您执行AssignProcessToJobObject,但仅当您在调试器中运行时,它会因“访问被拒绝”而失败。 为什么是这样?

You do AssignProcessToJobObject and it fails with "access denied" but only when you are running in the debugger. Why is this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此岸叶落 2024-07-11 11:25:28

这似乎经常困扰着我,虽然很好,但 1800INFORMATION 的帖子似乎没有包含一些看起来有帮助的原因和修复方法,因此似乎值得发布我看到这种情况发生的原因的摘要。

  1. 当尝试自己解决这个问题时,请注意这个问题
    从 CMD.EXE、资源管理器运行时,可能会因不同原因发生
    和视觉工作室。 尝试从以下位置运行失败的可执行文件
    相应的地方可以帮助找出问题的原因。 你
    尽管从 VS 失败,但应用程序可能只能从 CMD.EXE 找到
    和 Explorer.exe
  2. 就我而言,在 Win7 下,我似乎需要取消注释“supportedOS”
    app.manifest 中指示 Win7 兼容性的元素
    文件。 这似乎解决了从资源管理器运行时的问题。 到
    添加清单,右键单击项目,点击添加,然后查找
    “应用程序清单文件”。
  3. 为了让 Visual Studio 2010 正常工作,我似乎需要阻止它使用程序兼容性助手,Tom Minka 在这里分享了两种方法:https://stackoverflow.com/a/4232259/86375,注意,我必须重新启动 VS2010 才能接受他建议的更改。

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.

  1. When trying to solve this for yourself, note than this problem
    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
  2. In my case, under Win7, I seemed to need to un-comment the "supportedOS"
    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'.
  3. To get Visual Studio 2010 working, I seemed to need to stop it from using the Program Compatibility Assistant, Tom Minka shares two ways to do this here: https://stackoverflow.com/a/4232259/86375, note, I had to restart VS2010 to take his suggested changes.
三五鸿雁 2024-07-11 11:25:28

这个问题让我困惑了大约30分钟。

首先,您可能需要在应用程序中嵌入 UAC 清单(

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <!-- Identify the application security requirements. -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"/>
        </requestedPrivileges>
      </security>
    </trustInfo>
  </assembly>

其次(这是我陷入困境的一点),当您在调试器下运行应用程序时,它会在作业对象中创建您的进程。 您的子进程需要能够脱离它,然后才能将其分配给您的工作。 所以(废话),您需要在 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:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <!-- Identify the application security requirements. -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"/>
        </requestedPrivileges>
      </security>
    </trustInfo>
  </assembly>

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 for CreateProcess).

If you weren't running under the debugger, or your parent process were in the job, this wouldn't have happened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文