且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AssignProcessToJobObject失败"拒绝访问"在调试器下运行时错误

更新时间:2021-10-01 01:48:02

这一次困扰了我30分钟左右。

This one puzzled me for for about 30 minutes.

首先,你可能需要一个UAC舱单嵌入在您的应用程序(as这里建议)。事情是这样的:

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>

其次(这是我被困在位),当你在调试器下运行你的应用程序,它会创建一个作业对象的过程。您的孩子的过程需要能够从之前您可以将其分配给您的工作,远走他乡。所以,(杜),你需要指定 CREATE_BREAKAWAY_FROM_JOB 中的标志的CreateProcess )。

如果你没有在调试器下运行,或者你的父进程都在工作,这将不会发生。

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