的确是权限的原因。VS调试正常是因为进程运行在调试权限下。
MSDN上说加入作业的进程句柄必需要有PROCESS_SET_QUOTA及PROCESS_TERMINATE权限。
hProcess
A handle to the process to associate with the job object. The process must not already be assigned to a job; if it is, the function fails with ERROR_ACCESS_DENIED. The handle must have the PROCESS_SET_QUOTA and PROCESS_TERMINATE access rights. For more information, see Process Security and Access Rights.
或者你在CreateProcess的第6个参数加入CREATE_BREAKAWAY_FROM_JOB试下
CREATE_BREAKAWAY_FROM_JOB|NORMAL_PRIORITY_CLASS |CREATE_SUSPENDED