180*_*ION 20 c c++ winapi createprocess
您这样做AssignProcessToJobObject
并且失败并显示"拒绝访问",但仅当您在调试器中运行时才会失败.为什么是这样?
180*_*ION 21
这个让我困惑了大约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>
Run Code Online (Sandbox Code Playgroud)
其次(这是我坚持的一点),当您在调试器下运行您的应用程序时,它会在作业对象中创建您的进程.您的子流程需要在将其分配到您的工作之前脱离.所以(duh),你需要CREATE_BREAKAWAY_FROM_JOB
在标志中指定 CreateProcess
).
如果您没有在调试器下运行,或者您的父进程在工作中,则不会发生这种情况.
这似乎经常让我感到困惑,虽然好,1800INFORMATION的帖子似乎并没有包括许多似乎有用的原因和修复,所以似乎有必要发布为什么我看到这种情况发生的总结.