AssignProcessToJobObject 拒绝访问

注意红色的部分,如果按照网上的说法还是有错误,加上红色的flag可能就好了。尤其是在win7 64 位中启动32位程序。具体原因msdn已经说得很清楚了。后附一段代码。
Remarks

After you associate a process with a job object using AssignProcessToJobObject, the process is subject to the limits set for the job. To set limits for a job, use the SetInformationJobObject function.

If the job has a user-mode time limit, and the time limit has been exhausted, AssignProcessToJobObject fails and the specified process is terminated. If the time limit would be exceeded by associating the process, AssignProcessToJobObject still succeeds. However, the time limit violation will be reported. If the job has an active process limit, and the limit would be exceeded by associating this process, AssignProcessToJobObject fails, and the specified process is terminated.

Memory operations performed by a process associated with a job that has a memory limit are subject to the memory limit. Memory operations performed by the process before it was associated with the job are not examined by AssignProcessToJobObject.

If the process is already running and the job has security limitations, AssignProcessToJobObject may fail. For example, if the primary token of the process contains the local administrators group, but the job object has the security limitation JOB_OBJECT_SECURITY_NO_ADMIN, the function fails. If the job has the security limitation JOB_OBJECT_SECURITY_ONLY_TOKEN, the process must be created suspended. To create a suspended process, call the CreateProcess function with the CREATE_SUSPENDED flag.

A process can be associated only with a single job. A process inherits limits from the job it is associated with and adds its accounting information to the job. If a process is associated with a job, all processes it creates are associated with that job by default. To create a process that is not part of the same job, call the CreateProcess function with the CREATE_BREAKAWAY_FROM_JOB flag.

If the process is being monitored by the Program Compatibility Assistant (PCA), it is placed into a compatibility job. Therefore, the process must be created using CREATE_BREAKAWAY_FROM_JOB before it can be placed in another job. Alternatively, you can embed an application manifest that specifies a User Account Control (UAC) level in your application and PCA will not add the process to the compatibility job.

To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the SDK Headers.


    PROCESS_INFORMATION     pi;   
    ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));   
    STARTUPINFO   si;   
    ZeroMemory(&si,sizeof(STARTUPINFO));   
    si.cb=sizeof(STARTUPINFO);   
    si.wShowWindow=SW_SHOW;   
    si.dwFlags=STARTF_USESHOWWINDOW;   
    BOOL   fRet=::CreateProcess(_T("C:\\windows\\explorer.exe"),   
    NULL,   
    NULL,   
    NULL,   
    FALSE,   
    NORMAL_PRIORITY_CLASS|CREATE_SUSPENDED,   
    NULL,   
    NULL,&si,&pi);   
    HANDLE hProcess=pi.hProcess;
    HANDLE hThread=pi.hThread;
    HANDLE hJob=CreateJobObject(NULL,_T("Tr0j4n"));
    BOOL bAss=AssignProcessToJobObject(hJob,hProcess);
    IsProcessInJob(hProcess,hJob,&bAss);
    ResumeThread(hThread);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Windows操作系统中,可以通过Windows API来实现将系统命名空间改为用户命名空间的操作。具体的实现方式如下: 1. 使用CreateJobObject API函数创建一个作业对象: ```c++ HANDLE hJob = CreateJobObject(NULL, NULL); ``` 2. 使用SetInformationJobObject API函数将作业对象的限制信息修改为用户命名空间: ```c++ JOBOBJECT_BASIC_LIMIT_INFORMATION jli = {0}; jli.LimitFlags = JOB_OBJECT_LIMIT_BREAKAWAY_OK | JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK; SetInformationJobObject(hJob, JobObjectBasicLimitInformation, &jli, sizeof(jli)); ``` 这里将JOB_OBJECT_LIMIT_BREAKAWAY_OK和JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK两个标志设置为1,表示允许进程从父进程的作业对象中“挣脱”出来,并拥有一个新的、基于用户命名空间的作业对象。 3. 使用CreateProcess API函数启动一个新的进程,并将其加入到作业对象中: ```c++ PROCESS_INFORMATION pi; STARTUPINFO si = {0}; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; CreateProcess(NULL, "cmd.exe", NULL, NULL, FALSE, CREATE_NEW_CONSOLE | CREATE_SUSPENDED, NULL, NULL, &si, &pi); AssignProcessToJobObject(hJob, pi.hProcess); ResumeThread(pi.hThread); ``` 这里启动一个新的cmd.exe进程,并将其加入到作业对象中。 通过以上步骤,就可以在Windows操作系统中将系统命名空间改为用户命名空间了。需要注意的是,这种操作需要具备足够的系统权限,并且不建议在生产环境中随意使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值