AdjustTokenPrivileges()函数怎么用?如何让SE_SHUTDOWN_NAME成为enable

解决方案 »

  1.   


    procedure TForm1.AdjustToken();varhdlProcessHandle : Cardinal;hdlTokenHandle : Cardinal;tmpLuid : Int64;tkpPrivilegeCount : Int64;tkp : TOKEN_PRIVILEGES;tkpNewButIgnored : TOKEN_PRIVILEGES;lBufferNeeded : Cardinal;Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;beginhdlProcessHandle := GetCurrentProcess;OpenProcessToken(hdlProcessHandle,(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),hdlTokenHandle);// Get the LUID for shutdown privilege.LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);Privilege[0].Luid := tmpLuid;Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;tkp.PrivilegeCount := 1; // One privilege to settkp.Privileges[0] := Privilege[0];// Enable the shutdown privilege in the access token of this// process.AdjustTokenPrivileges(hdlTokenHandle,False,tkp,Sizeof(tkpNewButIgnored),tkpNewButIgnored,lBufferNeeded);end;
     
     from:超级猛了