我在一个BUTTON中写了
SetSystemPowerState(False,True);
按下后一点反应都没有。请问有谁知道是怎么一回事

解决方案 »

  1.   

    在98可以,在2000,NT,xp下你要先取到SE_SHUTDOWN_NAME权限。
      

  2.   

    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;******************function SleepSystem():BOOL;varhProcess,hAccessToken:THandle;LUID_AND_ATTRIBUTES:TLUIDAndAttributes;TOKEN_PRIVILEGES: TTokenPrivileges;BufferIsNull:DWORD;ConstSE_SHUTDOWN_NAME='SeShutdownPrivilege';beginhProcess:=GetCurrentProcess();OpenProcessToken(hprocess,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hAccessToken);LookupPrivilegeValue(Nil,SE_SHUTDOWN_NAME,LUID_AND_ATTRIBUTES.Luid);LUID_AND_ATTRIBUTES.Attributes:=SE_PRIVILEGE_ENABLED;TOKEN_PRIVILEGES.PrivilegeCount:=1;TOKEN_PRIVILEGES.Privileges[0]:=LUID_AND_ATTRIBUTES;BufferIsNull:=0;AdjustTokenPrivileges(hAccessToken,False,TOKEN_PRIVILEGES,sizeof(TOKEN_PRIVILEGES),Nil,BufferIsNull);SetSystemPowerState(False,True);ShutDownSystem:=True;end;
      

  3.   

    呵呵,刚刚帮你试过得了,系统2003!休眠状态!
    参看大富翁http://www.delphibbs.com/delphibbs/dispq.asp?lid=903658function SetPrivilege(
     sPrivilegeName : string;
     bEnabled : boolean )
       : boolean;
    var
     TPPrev,
     TP         : TTokenPrivileges;
     Token      : THandle;
     dwRetLen   : DWord;
    begin
     Result := False; OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,Token ); TP.PrivilegeCount := 1;
     if( LookupPrivilegeValue(
           Nil,
           PChar( sPrivilegeName ),
           TP.Privileges[ 0 ].LUID ) )then
     begin
       if( bEnabled )then
       begin
         TP.Privileges[ 0 ].Attributes  :=
           SE_PRIVILEGE_ENABLED;
       end else
       begin
         TP.Privileges[ 0 ].Attributes  :=
           0;
       end;   dwRetLen := 0;
       Result := AdjustTokenPrivileges(
                   Token,
                   False,
                   TP,
                   SizeOf( TPPrev ),
                   TPPrev,
                   dwRetLen );
     end;
     CloseHandle( Token );
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SetPrivilege( 'SeShutdownPrivilege', True );   //获取权限!
      SetSystemPowerState(true,true)
    end;end.
      

  4.   

    thank you very very :d