回复 15楼 beyondyf
恩 windows server 2003的杨大哥 我就算是回来看看吧 因为我下学期就不来了 还有两个星期放假
虽然说以后不准备干这行了,但是我还是舍不得这个论坛,毕竟在这呆了两年多了
还认识了很多好朋友,以后就把编程当做一个兴趣爱好啦。呵呵 就像杨大哥那样
[ 本帖最后由 laoyang103 于 2012-12-25 15:10 编辑 ]
===========深入<----------------->浅出============
#include <stdio.h> #include <windows.h> #include <winbase.h> #define MEM_LIMIT 4096*1000 int main(int argc, char* argv[]) { HANDLE hjob; char *job_name="J1",*pro_name="notepad"; int err; JOBOBJECT_EXTENDED_LIMIT_INFORMATION joeli; JOBOBJECT_SECURITY_LIMIT_INFORMATION securityLimit; ZeroMemory(&securityLimit, sizeof(securityLimit)); JOBOBJECT_BASIC_LIMIT_INFORMATION jbii={0}; STARTUPINFOA si ={sizeof(si)}; PROCESS_INFORMATION pi; if((hjob=CreateJobObjectA(NULL,job_name))==NULL) { printf("Cannot create job!\n"); return 1; } joeli.BasicLimitInformation.LimitFlags=JOB_OBJECT_LIMIT_PROCESS_MEMORY; joeli.ProcessMemoryLimit=MEM_LIMIT; if(SetInformationJobObject(hjob,JobObjectExtendedLimitInformation,&joeli,sizeof(joeli))==0) { err=GetLastError(); printf("Fail to set job attributes, Error Code:%d\n",err); return 1; } if(CreateProcessA(NULL,pro_name,NULL ,NULL,FALSE,CREATE_BREAKAWAY_FROM_JOB ,NULL,NULL,&si,&pi)==0) { err=GetLastError(); printf("Cannot create Process %s, Error Code:%d\n",pro_name,err); return 1; } if(!AssignProcessToJobObject(hjob,pi.hProcess)) { err=GetLastError(); printf("Fail to assign process to job Eror Code:%d\n",err); } ResumeThread(pi.hThread); WaitForSingleObject(pi.hProcess,INFINITE); return 0; }
#include <stdio.h> #include <windows.h> #include <winbase.h> #define MEM_LIMIT 4096*1000 int main(int argc, char* argv[]) { HANDLE hjob; char *job_name="J1",*pro_name="notepad"; int err; JOBOBJECT_EXTENDED_LIMIT_INFORMATION joeli; JOBOBJECT_SECURITY_LIMIT_INFORMATION securityLimit; ZeroMemory(&securityLimit, sizeof(securityLimit)); JOBOBJECT_BASIC_LIMIT_INFORMATION jbii={0}; STARTUPINFOA si ={sizeof(si)}; PROCESS_INFORMATION pi; //以下代码主要功能就是提权 HANDLE hToken; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess() ,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY ,&hToken)) { return false; } if ( !LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid ) ) { CloseHandle( hToken ); return false; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if ( !AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL ) ) { CloseHandle( hToken ); return false; } //以上所有代码都是为了提权,是为下面的函数做准备工作的*/ if((hjob=CreateJobObjectA(NULL,job_name))==NULL) { printf("Cannot create job!\n"); return 1; } joeli.BasicLimitInformation.LimitFlags=JOB_OBJECT_LIMIT_PROCESS_MEMORY; joeli.ProcessMemoryLimit=MEM_LIMIT; if(SetInformationJobObject(hjob,JobObjectExtendedLimitInformation,&joeli,sizeof(joeli))==0) { err=GetLastError(); printf("Fail to set job attributes, Error Code:%d\n",err); return 1; } if(CreateProcessA(NULL,pro_name,NULL ,NULL,FALSE,CREATE_BREAKAWAY_FROM_JOB ,NULL,NULL,&si,&pi)==0) { err=GetLastError(); printf("Cannot create Process %s, Error Code:%d\n",pro_name,err); return 1; } if(!AssignProcessToJobObject(hjob,pi.hProcess)) { err=GetLastError(); printf("Fail to assign process to job Eror Code:%d\n",err); } ResumeThread(pi.hThread); WaitForSingleObject(pi.hProcess,INFINITE); return 0; }貌似25-26楼的代码都可以的