home *** CD-ROM | disk | FTP | other *** search
- unit Sched;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, Consts, ShellAPI, ToolHelp, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- AppStyle: TComboBox;
- AppList: TListBox;
- StartTime: TEdit;
- StopTime: TEdit;
- BitBtn1: TBitBtn;
- BitBtn2: TBitBtn;
- BitBtn3: TBitBtn;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- ProgramList: TOpenDialog;
- SelectedList: TListBox;
- OptionsList: TListBox;
- StartList: TListBox;
- StopList: TListBox;
- Label4: TLabel;
- StatusList: TListBox;
- Status: TEdit;
- Timer1: TTimer;
- RunToday: TListBox;
- Label5: TLabel;
- StillToRun: TEdit;
- TimeStampList: TListBox;
- Label6: TLabel;
- LastCheck: TLabel;
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn3Click(Sender: TObject);
- procedure AppListClick(Sender: TObject);
- procedure AlterStartTime(Sender: TObject);
- procedure AlterStopTime(Sender: TObject);
- procedure AlterOptions(Sender: TObject);
- function ExecuteFile(const FileName, Params, DefaultDir: string;
- ShowCmd: Integer; Item: Integer): THandle;
- procedure CheckList(Sender: TObject);
- procedure SchedulerSetup(Sender: TObject);
- procedure AlterRun(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure AlterStillToRun(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- WindowHandles : Array [0..100] of HWnd;
- AppItems : Integer;
- TodayDate : String;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.SchedulerSetup(Sender: TObject);
-
- Var
-
- Application : String;
- Start : String;
- Stop : String;
- Options : String;
- Status : String;
- RunT : String;
- TimeS : String;
-
- n : Integer;
- LastSlash : Integer;
-
- Response : Word;
-
- ReturnFocus : HWnd;
-
- QuitRes : LongInt;
-
- ApplicationName : String;
- DirectoryT : String;
-
-
- Input : TextFile;
-
- begin
-
- (* This procedure sets up Scheduler for operation *)
-
- TodayDate:=DateToStr(Date);
-
- (* Load the program entries *)
-
- If FileExists('C:\SCHEDULE\PROGRAMS.DAT') then
- begin
- AssignFile(Input,'C:\SCHEDULE\PROGRAMS.DAT');
- Reset(Input);
- ReadLn(Input,TodayDate);
- Repeat
- ReadLn(Input,Application);
- ReadLn(Input,Start);
- ReadLn(Input,Stop);
- ReadLn(Input,Options);
- ReadLn(Input,Status);
- ReadLn(Input,RunT);
- ReadLn(Input,TimeS);
- AppList.Items.Add(Application);
- OptionsList.Items.Add(Options);
- StartList.Items.Add(Start);
- StopList.Items.Add(Stop);
- StatusList.Items.Add(Status);
- RunToday.Items.Add(RunT);
- TimeStampList.Items.Add(TimeS);
- Inc(AppItems);
- Until Eof(Input);
- CloseFile(Input);
- end;
- end;
-
-
- procedure TForm1.BitBtn1Click(Sender: TObject);
-
- Var
- n : Integer;
-
- begin
-
- (* This procedure adds applications to the list *)
-
- Status.Text:='DOP';
-
- If ProgramList.Execute then;
- SelectedList.Items:=ProgramList.Files;
-
- AppList.Items.Add(SelectedList.Items.Strings[0]);
- OptionsList.Items.Add('SW_SHOW');
- StartList.Items.Add('Never');
- StopList.Items.Add('Never');
- StatusList.Items.Add('Inactive');
- RunToday.Items.Add('Yes');
- TimeStampList.Items.Add('Not Run');
- Inc(AppItems);
- If AppList.ItemIndex=-1 then
- Status.Text:=''
- else
- Status.Text:=StatusList.Items.Strings[AppList.ItemIndex];
-
- end;
-
- procedure TForm1.BitBtn3Click(Sender: TObject);
-
- var
-
- n,q: Integer;
-
-
- begin
-
- (* This procedure exits scheduler *)
-
- (* Rewrite the file *)
-
- q:=AppItems;
- AssignFile(Output,'C:\SCHEDULE\PROGRAMS.DAT');
- ReWrite(Output);
- WriteLn(Output,TodayDate);
- For n:=1 to q do
- begin
- WriteLn(Output,AppList.Items.Strings[n-1]);
- WriteLn(Output,StartList.Items.Strings[n-1]);
- WriteLn(Output,StopList.Items.Strings[n-1]);
- WriteLn(Output,OptionsList.Items.Strings[n-1]);
- WriteLn(Output,StatusList.Items.Strings[n-1]);
- WriteLn(Output,RunToday.Items.Strings[n-1]);
- WriteLn(Output,TimeStampList.Items.Strings[n-1]);
- end;
- CloseFile(Output);
-
- Halt;
- end;
-
- procedure TForm1.AppListClick(Sender: TObject);
-
- begin
-
- (* This procedure displays information on the application selected *)
-
- StartTime.Text:=StartList.Items.Strings[AppList.ItemIndex];
- StopTime.Text:=StopList.Items.Strings[AppList.ItemIndex];
- AppStyle.Text:=OptionsList.Items.Strings[AppList.ItemIndex];
- Status.Text:=StatusList.Items.Strings[AppList.ItemIndex];
- StillToRun.Text:=RunToday.Items.Strings[AppList.ItemIndex];
-
- end;
-
- procedure TForm1.AlterStartTime(Sender: TObject);
-
- Var
-
- n : Integer;
- LastSlash : Integer;
- ApplicationName : String;
- DirectoryT : String;
-
- begin
-
- (* This procedure checks what actions are required after the start time has been changed *)
-
- If UpperCase(StartTime.Text[1])='A' then
- StartTime.Text:='Always';
-
- StartList.Items.Strings[AppList.ItemIndex]:=StartTime.Text;
-
- Application.ProcessMessages;
-
- If (StartTime.Text='Always') and (Status.Text='Inactive') then
- begin
- Screen.Cursor:=crHourGlass;
- Status.Text:='Starting';
- Application.ProcessMessages;
- LastSlash:=0;
- DirectoryT:='';
- ApplicationName:=AppList.Items.Strings[AppList.ItemIndex];
- For n:=0 to Length(AppList.Items.Strings[AppList.ItemIndex]) do
- begin
- If ApplicationName[n]='\' then
- LastSlash:=n;
- end;
-
- If LastSlash>0 then
- begin
- Inc(LastSlash);
- DirectoryT:=Copy(ApplicationName,LastSlash,Length(ApplicationName)-LastSlash);
- end;
-
- Status.Text:='Active';
- StatusList.Items.Strings[AppList.ItemIndex]:=Status.Text;
- RunToday.Items.Strings[AppList.ItemIndex]:='No';
- StillToRun.Text:='No';
- Screen.Cursor:=crDefault;
- Application.ProcessMessages;
-
- If AppStyle.Text='SW_MINIMIZE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_MINIMIZE,AppList.ItemIndex);
- If AppStyle.Text='SW_RESTORE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_RESTORE,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOW' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOW,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWMAXIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMAXIMIZED,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWMINIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINIMIZED,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWMINNOACTIVE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINNOACTIVE,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWNA' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNA,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWNOACTIVATE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNOACTIVATE,AppList.ItemIndex);
- If AppStyle.Text='SW_SHOWNORMAL' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNORMAL,AppList.ItemIndex);
- end;
-
- Application.ProcessMessages;
-
- end;
-
- procedure TForm1.AlterStopTime(Sender: TObject);
-
- Var
-
- Response : Word;
- ReturnFocus : HWnd;
- QuitRes : LongInt;
-
- begin
-
- (* This procedure checks what actions are required after the stop time has been changed *)
-
- If UpperCase(StopTime.Text[1])='I' then
- StopTime.Text:='Immediate';
-
- StopList.Items.Strings[AppList.ItemIndex]:=StopTime.Text;
-
- If (StopTime.Text='Immediate') and (Status.Text='Active') then
- begin
- Screen.Cursor:=crHourGlass;
- Status.Text:='Closing';
- QuitRes:=SendMessage(WindowHandles[AppList.ItemIndex],WM_CLOSE,0,0);
- Application.ProcessMessages;
- Status.Text:='Inactive';
- StatusList.Items.Strings[AppList.ItemIndex]:=Status.Text;
- RunToday.Items.Strings[AppList.ItemIndex]:='No';
- StillToRun.Text:='No';
- StopTime.Text:='Never';
- StopList.Items.Strings[AppList.ItemIndex]:=StopTime.Text;
- Screen.Cursor:=crDefault;
-
- end;
- end;
-
- procedure TForm1.AlterOptions(Sender: TObject);
- begin
- OptionsList.Items.Strings[AppList.ItemIndex]:=AppStyle.Text;
- end;
-
- procedure TForm1.CheckList(Sender: TObject);
-
- Var
-
- n : Integer;
- o : Integer;
- q : Integer;
- LastSlash : Integer;
-
- Process : Boolean;
-
- Response : Word;
-
- ReturnFocus : HWnd;
-
- QuitRes : LongInt;
-
- ApplicationName : String;
- DirectoryT : String;
-
- TestDate : String[8];
-
- Output : TextFile;
-
- begin
-
- (* Check actions required *)
-
- (* Check it is not the weekend *)
-
- Application.ProcessMessages;
- q:=AppItems;
- Application.ProcessMessages;
- Process:=False;
- Application.ProcessMessages;
- For n:=1 to q do
- begin
- If RunToday.Items.Strings[n-1]='Yes' then
- Process:=True;
- Application.ProcessMessages;
- end;
-
- If ((DayOfWeek(Now)<>2) and (DayOfWeek(Now)<>7)) or (Process) then
- begin
-
- (* Scan the programs list to see if any actions required *)
-
- Application.ProcessMessages;
- (* Screen.Cursor:=crHourGlass;*)
- TestDate:=DateToStr(Date);
- Application.ProcessMessages;
- LastCheck.Caption:='Last Checked @ '+TimeToStr(Time)+' on '+TestDate;
- Application.ProcessMessages;
-
- If TodayDate<>TestDate then
- begin
- For n:=1 to q do
- begin
- RunToday.Items.Strings[n-1]:='Yes';
- Application.ProcessMessages;
- end;
- TodayDate:=TestDate;
- Application.ProcessMessages;
- end;
-
- If q>0 then
- begin
- For n:=1 to q do
- begin
-
- (* Check active applications are still active *)
-
- ReturnFocus:=WinProcs.SetFocus(WindowHandles[n-1]);
- If ReturnFocus=0 then
- StatusList.Items.Strings[n-1]:='Inactive';
- Application.ProcessMessages;
- end;
- end;
-
- If (q>0) and (Status.Text<>'DOP') then
- begin
-
- (* Rewrite the file *)
-
- AssignFile(Output,'C:\SCHEDULE\PROGRAMS.DAT');
- ReWrite(Output);
- WriteLn(Output,TodayDate);
- Application.ProcessMessages;
- For n:=1 to q do
- begin
- WriteLn(Output,AppList.Items.Strings[n-1]);
- WriteLn(Output,StartList.Items.Strings[n-1]);
- WriteLn(Output,StopList.Items.Strings[n-1]);
- WriteLn(Output,OptionsList.Items.Strings[n-1]);
- WriteLn(Output,StatusList.Items.Strings[n-1]);
- WriteLn(Output,RunToday.Items.Strings[n-1]);
- WriteLn(Output,TimeStampList.Items.Strings[n-1]);
- Application.ProcessMessages;
- end;
- CloseFile(Output);
-
- For n:=1 to q do
- begin
- Application.ProcessMessages;
- StartTime.Text:=StartList.Items.Strings[n-1];
- StopTime.Text:=StopList.Items.Strings[n-1];
- AppStyle.Text:=OptionsList.Items.Strings[n-1];
- Status.Text:=StatusList.Items.Strings[n-1];
- StillToRun.Text:=RunToday.Items.Strings[n-1];
-
- if (StartTime.Text='Always') and (Status.Text='Inactive') and (StillToRun.Text='Yes') then
- begin
- Application.ProcessMessages;
- Screen.Cursor:=crHourGlass;
- Application.ProcessMessages;
- Status.Text:='Starting';
- Application.ProcessMessages;
- LastSlash:=0;
- DirectoryT:='';
- ApplicationName:=AppList.Items.Strings[n-1];
- Application.ProcessMessages;
- For o:=0 to Length(AppList.Items.Strings[n-1]) do
- begin
- If ApplicationName[o]='\' then
- LastSlash:=o;
- Application.ProcessMessages;
- end;
-
- If LastSlash>0 then
- begin
- Inc(LastSlash);
- DirectoryT:=Copy(ApplicationName,LastSlash,Length(ApplicationName)-LastSlash);
- end;
- Application.ProcessMessages;
- If AppStyle.Text='SW_MINIMIZE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_MINIMIZE,n-1);
- If AppStyle.Text='SW_RESTORE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_RESTORE,n-1);
- If AppStyle.Text='SW_SHOW' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOW,n-1);
- If AppStyle.Text='SW_SHOWMAXIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMAXIMIZED,n-1);
- If AppStyle.Text='SW_SHOWMINIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINIMIZED,n-1);
- If AppStyle.Text='SW_SHOWMINNOACTIVE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINNOACTIVE,n-1);
- If AppStyle.Text='SW_SHOWNA' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNA,n-1);
- If AppStyle.Text='SW_SHOWNOACTIVATE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNOACTIVATE,n-1);
- If AppStyle.Text='SW_SHOWNORMAL' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNORMAL,n-1);
- Application.ProcessMessages;
- Status.Text:='Active';
- StatusList.Items.Strings[n-1]:=Status.Text;
- RunToday.Items.Strings[n-1]:='No';
- StillToRun.Text:='No';
- Application.ProcessMessages;
- Screen.Cursor:=crDefault;
- end;
-
-
- If (StartTime.Text<>'Never') and (StartTime.Text<>'Always') and (StillToRun.Text='Yes') then
- begin
- If (StrToTime(StartTime.Text)<=Time) and (Status.Text<>'Active') then
- begin
- Status.Text:='Starting';
- Application.ProcessMessages;
- LastSlash:=0;
- DirectoryT:='';
- ApplicationName:=AppList.Items.Strings[n-1];
- Application.ProcessMessages;
- For o:=0 to Length(AppList.Items.Strings[n-1]) do
- begin
- If ApplicationName[o]='\' then
- LastSlash:=o;
- end;
- Application.ProcessMessages;
- If LastSlash>0 then
- begin
- Inc(LastSlash);
- DirectoryT:=Copy(ApplicationName,LastSlash,Length(ApplicationName)-LastSlash);
- Application.ProcessMessages;
- end;
-
- If AppStyle.Text='SW_MINIMIZE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_MINIMIZE,n-1);
- If AppStyle.Text='SW_RESTORE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_RESTORE,n-1);
- If AppStyle.Text='SW_SHOW' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOW,n-1);
- If AppStyle.Text='SW_SHOWMAXIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMAXIMIZED,n-1);
- If AppStyle.Text='SW_SHOWMINIMIZED' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINIMIZED,n-1);
- If AppStyle.Text='SW_SHOWMINNOACTIVE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWMINNOACTIVE,n-1);
- If AppStyle.Text='SW_SHOWNA' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNA,n-1);
- If AppStyle.Text='SW_SHOWNOACTIVATE' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNOACTIVATE,n-1);
- If AppStyle.Text='SW_SHOWNORMAL' then
- ExecuteFile(ApplicationName,'',DirectoryT,SW_SHOWNORMAL,n-1);
- Application.ProcessMessages;
- Status.Text:='Active';
- StatusList.Items.Strings[n-1]:=Status.Text;
- RunToday.Items.Strings[n-1]:='No';
- StillToRun.Text:='No';
- Application.ProcessMessages;
- end;
- end;
- if (StopTime.Text<>'Never') and (StopTime.Text<>'Immediate') then
- begin
- If (StrToTime(StopTime.Text)<=Time) and (Status.Text<>'Inactive') then
- begin
- Status.Text:='Closing';
- RunToday.Items.Strings[n-1]:='No';
- Application.ProcessMessages;
- QuitRes:=SendMessage(WindowHandles[n-1],WM_CLOSE,0,0);
- Application.ProcessMessages;
- Status.Text:='Inactive';
- StatusList.Items.Strings[n-1]:=Status.Text;
- end;
- end;
- end;
-
- If AppList.ItemIndex>-1 then
- begin
- Application.ProcessMessages;
- StartTime.Text:=StartList.Items.Strings[AppList.ItemIndex];
- Application.ProcessMessages;
- StopTime.Text:=StopList.Items.Strings[AppList.ItemIndex];
- Application.ProcessMessages;
- AppStyle.Text:=OptionsList.Items.Strings[AppList.ItemIndex];
- Application.ProcessMessages;
- Status.Text:=StatusList.Items.Strings[AppList.ItemIndex];
- Application.ProcessMessages;
- StillToRun.Text:=RunToday.Items.Strings[AppList.ItemIndex];
- end;
- end;
- Screen.Cursor:=crDefault;
- end else
- begin
- LastCheck.Caption:='Scan inactive due to weekend';
- end;
- Application.ProcessMessages;
-
-
- end;
-
-
- procedure TForm1.AlterRun(Sender: TObject);
- begin
- If StillToRun.Text='Yes' then
- RunToday.Items.Strings[AppList.ItemIndex]:='Yes';
-
- If StillToRun.Text<>'Yes' then
- begin
- StillToRun.Text:='No';
- RunToday.Items.Strings[AppList.ItemIndex]:='No';
- end;
-
- end;
-
- procedure TForm1.BitBtn2Click(Sender: TObject);
- begin
-
- (* This procedure deletes entries from the application list *)
-
- AppList.Items.Delete(AppList.ItemIndex);
- StartList.Items.Delete(AppList.ItemIndex);
- StopList.Items.Delete(AppList.ItemIndex);
- OptionsList.Items.Delete(AppList.ItemIndex);
- StatusList.Items.Delete(AppList.ItemIndex);
- RunToday.Items.Delete(AppList.ItemIndex);
- TimeStampList.Items.Delete(AppList.ItemIndex);
- Dec(AppItems);
-
- end;
-
- procedure TForm1.AlterStillToRun(Sender: TObject);
- begin
-
- If StillToRun.Text<>'Yes' then
- begin
- StillToRun.Text:='No';
- RunToday.Items.Strings[AppList.ItemIndex]:='No';
- end;
-
- If StillToRun.Text='Yes' then
- begin
- StillToRun.Text:='Yes';
- RunToday.Items.Strings[AppList.ItemIndex]:='Yes';
- end;
-
- end;
-
- function TForm1.ExecuteFile(const FileName, Params, DefaultDir: string;
- ShowCmd: Integer; Item: Integer): THandle;
- var
- zFileName, zParams, zDir: array[0..79] of Char;
- begin
- Result:=ShellExecute( Application.MainForm.Handle, nil,
- StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
- StrPCopy(zDir, DefaultDir), ShowCmd);
-
- WindowHandles[Item]:=WinProcs.GetFocus;
-
- (* Update time stamp for this item *)
-
- TimeStampList.Items.Strings[Item]:=TimeToStr(Time);
-
- end;
-
-
- end.
-