
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, Mask, DBCtrls, ExtCtrls, DB, DBTables,
  AdvAlertWindow,ShellAPI,Tlhelp32, MPlayer, ADODB,DateUtils, WebCopy,
  WinExit;

type
  TForm3 = class(TForm)
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBGrid1: TDBGrid;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Edit3: TEdit;
    DataSource1: TDataSource;
    AdvAlertWindow1: TAdvAlertWindow;
    Timer1: TTimer;
    MediaPlayer1: TMediaPlayer;
    ADOTable1: TADOTable;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    WebCopy1: TWebCopy;
    WinExit1: TWinExit;
    WinExit2: TWinExit;
    procedure Timer1Timer(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;
implementation

uses Unit1, Unit2, Unit4;

{$R *.dfm}
function KillTask(Dosyadi: string): integer;
const
PROCESS_TERMINATE=$0001;
var
devam: BOOL;
fyakhandle: THandle;
islem32: TProcessEntry32;
begin
result := 0;

fyakhandle := CreateToolhelp32Snapshot
                     (TH32CS_SNAPPROCESS, 0);
islem32.dwSize := Sizeof(islem32);
devam := Process32First(fyakhandle,
                                 islem32);

  while integer(devam) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(islem32.szExeFile)) =
         UpperCase(Dosyadi))
     or (UpperCase(islem32.szExeFile) =
         UpperCase(Dosyadi))) then
      Result := Integer(TerminateProcess(OpenProcess(
                        PROCESS_TERMINATE, BOOL(0),
                        islem32.th32ProcessID), 0));
    devam := Process32Next(fyakhandle,
                                  islem32);
  end;

  CloseHandle(fyakhandle);
end;


procedure TForm3.Timer1Timer(Sender: TObject);
var
x:integer;
begin
if x>ADOTable1.RecordCount then timer1.Enabled:=false;
ADOTable1.Filter := '(COMPLETIONDATE='''+edit2.text+''') and (TIME='''+edit3.Text+''')';
 ADOTable1.Filtered := True;
For x:=1 to ADOTable1.RecordCount do
begin
with AdvAlertWindow1.AlertMessages.Add do
      begin
        Text.Text := 'Subject: '+DBEdit1.Text+' Event: '+DBedit5.text+' Time: '+DBEdit2.Text+','+DBedit4.Text;
      end;
      if DBEdit5.Text='Run Program'  then
        WinExec(pchar(DBedit3.text),SW_SHOWNORMAL);
      if DBEdit5.Text='Open Website'  then
        ShellExecute(Handle, 'open',pchar(DBedit3.text),'','',SW_SHOWNORMAL);
      if DBEdit5.Text='Shutdown' then
        WinExit1.Execute;
      if DBEdit5.Text='Restart' then
        WinExit2.Execute;
      if DBEdit5.Text='Kill Program' then
        KillTask(DBEdit3.Text);
      if DBEdit5.Text='Download' then
      begin
        With WebCopy1.Items.Add do
          begin
            URL := pchar(DBedit3.text);
            TargetDir := 'c:\Downloads';
            end;
          WebCopy1.Execute;
       end;
  if dbedit6.Text='' then MediaPlayer1.FileName:='.\alarm.wav'
    else
      MediaPlayer1.FileName:=dbedit6.text;
MediaPlayer1.Play;
ADOTable1.Delete;
ADOTable1.Next;
AdvAlertWindow1.Show;
form1.ADOTable1.Active:=false;
form3.ADOTable1.Active:=false;
form1.ADOTable1.Active:=true;
form3.ADOTable1.Active:=true;
end
end;

procedure TForm3.Edit3Change(Sender: TObject);
begin
timer1.Enabled:=true;
end;

end.


