unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, DB, DBTables, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Query: TQuery;<br> Edit1: TEdit;<br> Button3: TButton;<br> Timer1: TTimer;<br> Edit2: TEdit;<br> Edit3: TEdit;<br> Edit4: TEdit;<br> Edit5: TEdit;<br> Edit6: TEdit;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br><br>implementation<br>function ShutDown(uFlags: Cardinal):boolean;<br>const<br> ADJUST_PRIV = TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES;<br> SHTDWN_PRIV = 'SeShutdownPrivilege';<br> PRIV_SIZE = sizeOf(TTokenPrivileges);<br>var<br> Len: DWORD;<br> TokenPriv, Dummy: TTokenPrivileges;<br> Token: THandle;<br> Error:integer;<br>begin<br> error:=0;<br> // 设置特权<br> // Delphi2:<br> //if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, @Token) then<br> if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, Token) then<br> Error := Error or 4;<br> if not LookupPrivilegeValue(nil, SHTDWN_PRIV,TokenPriv.Privileges[0].Luid) then<br> Error := Error or 8;<br> TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br> TokenPriv.PrivilegeCount := 1; // One privilege to set<br> if not AdjustTokenPrivileges(Token, false, TokenPriv, PRIV_SIZE,Dummy, Len) then<br> Error:=Error or 16;<br> ExitWindowsEx(uFlags, 0);<br> Result := (Error=0);<br>end;<br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>if(formatdatetime('hh',now)=edit1.Text)then<br>ShutDown(EWX_POWEROFF + EWX_FORCE);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>Showmessage(datetimetostr(now));<br>showmessage(formatdatetime('hh',now));<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br> ShutDown(EWX_POWEROFF + EWX_FORCE);<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>button1.Click;<br>end;<br><br>end.<br>