精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>其他>>Re:help!!!如何获得SE_SHUTDOWN_NAME 特权

主题:Re:help!!!如何获得SE_SHUTDOWN_NAME 特权
发信人: kingron( )
整理人: delfan(2001-04-16 16:17:12), 站内信件
procedure TForm1.AdjustToken();
var
  hdlProcessHandle : Cardinal;
  hdlTokenHandle : Cardinal;
  tmpLuid : Int64;
  tkpPrivilegeCount : Int64;
  tkp : TOKEN_PRIVILEGES;
  tkpNewButIgnored : TOKEN_PRIVILEGES;
  lBufferNeeded : Cardinal;
  Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
        hdlProcessHandle := 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 set
        tkp.Privileges[0] := Privilege[0];
        // Enable the shutdown privilege in the access token of this
        // process.
        AdjustTokenPrivileges(hdlTokenHandle,
                              False,
                              tkp,
                              Sizeof(tkpNewButIgnored),
                              tkpNewButIgnored,
                              lBufferNeeded);

end;



----
<img src="http://uh1.gz.163.com photo?name=kingron" border=0 alt="我是谁?">  

[关闭][返回]