1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
| unit windows_u;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Mask, Buttons;
type TForm1 = class(TForm) Image1: TImage; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; RadioButton4: TRadioButton; RadioButton5: TRadioButton; RadioButton6: TRadioButton; Bildschirmschoner: TRadioButton; MaskEdit1: TMaskEdit; MaskEdit2: TMaskEdit; Button1: TButton; Timer1: TTimer; Button2: TButton; MaskEdit3: TMaskEdit; Timer2: TTimer; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Button3: TButton; Button4: TButton; procedure RadioButton1Click(Sender: TObject); procedure RadioButton2Click(Sender: TObject); procedure RadioButton3Click(Sender: TObject); procedure RadioButton4Click(Sender: TObject); procedure RadioButton5Click(Sender: TObject); procedure RadioButton6Click(Sender: TObject); procedure BildschirmschonerClick(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private public end;
var Form1: TForm1;
implementation
{$R *.DFM}
function WindowsExit(RebootParam: Longword): Boolean; var TTokenHd: THandle; TTokenPvg: TTokenPrivileges; cbtpPrevious: DWORD; rTTokenPvg: TTokenPrivileges; pcbtpPreviousRequired: DWORD; tpResult: Boolean; const SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin tpResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHd) ; if tpResult then begin tpResult := LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, TTokenPvg.Privileges[0].Luid) ; TTokenPvg.PrivilegeCount := 1; TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; cbtpPrevious := SizeOf(rTTokenPvg) ; pcbtpPreviousRequired := 0; if tpResult then Windows.AdjustTokenPrivileges(TTokenHd, False, TTokenPvg, cbtpPrevious, rTTokenPvg, pcbtpPreviousRequired) ; end; end; Result := ExitWindowsEx(RebootParam, 0) ; end;
procedure TForm1.RadioButton1Click(Sender: TObject); begin ExitWindowsEx(EWX_SHUTDOWN, 0); end;
procedure TForm1.RadioButton2Click(Sender: TObject); begin ExitWindowsEx(EWX_REBOOT, 0); end;
procedure TForm1.RadioButton3Click(Sender: TObject); begin ExitWindowsEx(EWX_LOGOFF, 0); end;
procedure TForm1.RadioButton4Click(Sender: TObject); begin WindowsExit(EWX_POWEROFF or EWX_FORCE) end;
procedure TForm1.RadioButton5Click(Sender: TObject); begin WindowsExit(EWX_REBOOT or EWX_FORCE) end;
procedure TForm1.RadioButton6Click(Sender: TObject); begin SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 1); end;
procedure TForm1.BildschirmschonerClick(Sender: TObject); begin SendMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 1); end;
var endtime:TDateTime;
procedure TForm1.Button1Click(Sender: TObject); var i,j,k:integer; begin endtime:=Now+EncodeTime(StrToInt(maskEdit1.Text),StrToInt(maskEdit2.Text), StrToInt(maskEdit3.Text),0);
timer1.enabled:=true; timer2.enabled:=true; i:=strtoint(maskedit1.text); i:=i*60000; j:=strtoint(maskedit2.text); j:=j*3600000; k:=strtoint(maskedit3.text); k:=k*1000; timer1.Interval:=i+j+k; timer1.OnTimer:=Button2Click;
end;
procedure TForm1.Button2Click(Sender: TObject); begin WindowsExit(EWX_POWEROFF or EWX_FORCE) end;
procedure TForm1.FormCreate(Sender: TObject); begin timer1.Enabled:=false; timer2.Enabled:=false;
end;
procedure TForm1.Timer2Timer(Sender: TObject); var hh,mm,ss,ms:word; timetoend:TDateTime; begin timetoend:=endtime-Now; if timetoend<0 then timetoend:=0; DecodeTime(timetoend,hh,mm,ss,ms); maskEdit1.Text:=IntToStr(hh); maskEdit2.Text:=IntToStr(mm); maskEdit3.Text:=IntToStr(ss); if timetoend>0 then exit; Timer2.enabled:=false;
end;
procedure TForm1.Button3Click(Sender: TObject); begin timer1.enabled:=false; timer2.enabled:=false; end;
procedure TForm1.Button4Click(Sender: TObject); begin close; end;
end. |