if Messagebox(ShutdownForm.Handle,'你真的要关机吗?','询问',MB_iconquestion+MB_YESNO)=IDYES then
begin
ExitWindowsEx(ewx_shutdown,0);
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;
可以给98和2000以及xp关机!