SetSystemPowerState函数,请问谁会用? 我在一个BUTTON中写了SetSystemPowerState(False,True);按下后一点反应都没有。请问有谁知道是怎么一回事 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在98可以,在2000,NT,xp下你要先取到SE_SHUTDOWN_NAME权限。 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; 呵呵,刚刚帮你试过得了,系统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. thank you very very :d 哪位大侠知道double浮点数据类型64位中每位所代表的格式含义 DLL调用退出时的错误! 求Delphi5注册码(急,等待中) 新手请教~~~~~~~~~~~~望各位帮忙~ SELECT语法错误 本人初学DELPHI:关于WINDOWS消息的一个巨愚的问题,入即给分 急,,,关于数据库的问题 请问一下:陈桥五笔5.1使用后总是提示注册,好烦。在长期用户管理,请输入注册码中应输入什么呀。有谁有解决的办法。 50元解决一多线程问题? 请问如何将图片写入到数据库中? ServerSocket1.Socket.LocalAddress的问题 对象的引用概念〉???在线!
参看大富翁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.