if Application.MessageBox('确定關机?','確認關閉電腦',MB_YESNO )=IDYES then
begin
if RadioButton1.Checked=true then
ExitWindowsEx(EWX_LOGOFF,0) //以其他用戶身份登錄
else if RadioButton2.Checked=true then
ExitWindowsEx(EWX_SHUTDOWN,1) //安全關机
else if RadioButton3.Checked=true then
ExitWindowsEx(EWX_REBOOT,2) //重新啟動計算机
else if RadioButton4.Checked=true then
ExitWindowsEx(EWX_FORCE,4) //強行關机
else if RadioButton5.Checked=true then
ExitWindowsEx(EWX_POWEROFF,8); //關閉係統並關閉電源
end;
procedure tform1.ShutDown;
procedure AdjustToken(); //获取关机控制权
var
hdlProcessHandle, hdlTokenHandle, lBufferNeeded: Cardinal;
tmpLuid: Int64;
//tkpPrivilegeCount: Int64;
tkp, tkpNewButIgnored: TOKEN_PRIVILEGES;
Privilege: array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProc