星河湾海怡半岛户型图:delphi 7在xp下关机与重启和待机的代码? 谢谢!

来源:百度文库 编辑:高校问答 时间:2024/04/24 15:50:27

XP和Win2k差不多,我给你提供几个在Win2k下的函数,你在Xp下再试试,应该也是可以的:
------------------------
NT、2000下关机的函数

var

hToken:THandle;

tkp : TOKEN_PRIVILEGES;

ReturnLength : DWord;

begin

if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then

begin

application.Terminate;

end;

LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);

tkp.PrivilegeCount := 1;

tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;

ReturnLength :=0;

AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);

if (GetLastError() <> ERROR_SUCCESS) then

begin

application.Terminate;

end;

if (not ExitWindowsEx(EWX_POWEROFF, 0)) then

begin

application.Terminate;

end;

end;

end.

NT、2000下重起的函数

var

hToken:THandle;

tkp : TOKEN_PRIVILEGES;

ReturnLength : DWord;

begin

if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then

begin

application.Terminate;

end;

LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);

tkp.PrivilegeCount := 1;

tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;

ReturnLength :=0;

AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);

if (GetLastError() <> ERROR_SUCCESS) then

begin

application.Terminate;

end;

if (not ExitWindowsEx(EWX_REBOOT, 0)) then

begin

application.Terminate;

end;

end;

end.

NT、2000下注销的函数

exitwindowsex(ewx_force,0); //注销

关闭显示器

SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, 1) ;