delphi 7在xp下关机与重启和待机的代码? 谢谢!
来源:百度知道 编辑:UC知道 时间:2024/06/30 11:01:57
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.