AdjustTokenPrivileges()是一个API函数,到winAPI里查找
它的使用方法

解决方案 »

  1.   

    查了[1000多页的Windows API函数参考],也试了n次(n>20),失败,最终放弃…………
      

  2.   

    procedure shutdownComputer;
    var
       htoken:Thandle;
       tkp,ptoken:ttokenprivileges;
       rl:Cardinal;
       lpname:pchar;begin
         lpname:='SeShutdownPrivilege';
         if not ((OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken))) then
              exit;
         LookupPrivilegeValue(NIL,lpname,tkp.Privileges[0].Luid);
         tkp.PrivilegeCount:= 1;
         tkp.Privileges[0].Attributes:=2;
         ptoken.PrivilegeCount:=0;
         AdjustTokenPrivileges(hToken,FALSE,tkp,sizeof(ptoken),ptoken,rl);
         initiatesystemshutdown(nil,nil,0,false,false);end;
      

  3.   

    报告:没有搞定。
    initiatesystemshutdown(nil,nil,0,false,false)函数返回False,也就是说函数调用没有success!!
      

  4.   

    单步测试的结果:LookupPrivilegeValue和AdjustTokenPrivileges返回True;
    initiatesystemshutdown失败
      

  5.   

    sorry,结帐时间推迟到周1!!
    重申我的环境:
    Windows 2000 Advanced Server,Delphi 6,Administrator登陆