不懂,帮顶
[fly]存在即是合理[/fly]
#include<stdio.h> #include<windows.h> bool _closecomputer(int flag) { //以下代码主要功能就是提权 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; } //以上所有代码都是为了提权,是为下面的函数做准备工作的 //下面这个关机函数,如果权限不够,是不能被执行的 ExitWindowsEx(EWX_POWEROFF ,flag); return true; } int main(void) { _closecomputer(0); return 0; }为了测试这段代码 代价惨重啊
#include "stdio.h" #include "windows.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_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,/*JOB_OBJECT_ALL_ACCESS*/NULL,/*JOB_OBJECT_ALL_ACCESS*/NULL,FALSE,CREATE_SUSPENDED,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; }楼猪,帮你找到了一个能正确执行的程序段,我找到的代码是错误的 ,简单的修正了一下 就可以运行了