procedure TForm1.Timer1Timer(Sender: TObject);
var
iSec :integer;
hToken:THandle;
tkp : TOKEN_PRIVILEGES;
ReturnLength : DWord;
begin
if SpeedButton1.Caption = '&Stop' then
Begin
if edit3.Text = '' then edit3.Text := '00';
iSec := StrToInt(edit3.Text );
if iSec >0 then edit3.Text := IntToStr(iSec -1)
else begin
if edit3.Text = '' then edit3.Text := '00';
iSec := StrToInt (edit2.Text );
if iSec > 0 then
begin
edit2.Text := IntToStr(iSec -1);
edit3.Text := '59';
end
else begin
if edit3.Text = '' then edit3.Text := '00';
iSec := StrToInt (edit1.Text);
if iSec >0 then
begin
edit1.Text := IntToStr(iSec -1);
edit2.Text := '59';
edit3.Text := '59';
end
else begin
case combType.ItemIndex of
1 : iSec := EWX_SHUTDOWN;
2 : iSec := EWX_REBOOT;
3 : iSec := EWX_FORCE;
4 : iSec := EWX_POWEROFF;
5 : iSec := EWX_FORCEIFHUNG;
else
iSec := EWX_LOGOFF;
end;
timer1.Enabled := False;
// EXIT;
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(iSec , 0)) then
begin
application.Terminate;
end;
end;
end;
end;
End
Else
Begin
if CheckBox2.Checked then
upDateTimePicker
Else
upDateTimeValue;
End;
end;