프로그래밍/Delphi
[델파이소스] 작업스케쥴러 추가
프링글
2009. 8. 5. 13:53
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Pat_info = ^at_info;
at_info = record
JobTime: DWORD;
DaysOfMonth: DWORD;
DaysOfWeek: UCHAR;
Flags: UCHAR;
Command: LPWSTR;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
JOB_RUN_PERIODICALLY = $01; { in-/output flag }
JOB_EXEC_ERROR = $02; { output flag }
JOB_RUNS_TODAY = $04; { output flag }
JOB_ADD_CURRENT_DATE = $08; { input flag }
JOB_NONINTERACTIVE = $10; { in-/output flag }
var
Form1: TForm1;
implementation
{$R *.DFM}
function NetScheduleJobAdd(
aMachine: string; // empty string for local machine
aTime: DWORD; // millisec. from midnight
DaysOfMonth: DWORD; //bit 0: 1. day bit1: 2. day value=0: not assigned
DaysOfWeek: byte; //bit 0: Monday .... value=0: not assigned
Flags: byte; //
mycommand: Widestring): DWORD;
var hLib: THandle;
Flag: DWord;
Ergebnis: DWord;
P: function(Servername: LPCWSTR; Buffer: Pat_info; JobId: LPDWORD): DWord;
stdcall; // NetScheduleJobAdd
myatinfo: at_info;
pmyatinfo: pat_info;
begin
P := nil;
hLib := LoadLibrary('NETAPI32.DLL');
P := GetProcAddress(hLib, 'NetScheduleJobAdd');
myatinfo.JobTime := aTime;
myatinfo.DaysOfMonth := DaysOfMonth;
myatinfo.DaysOfWeek := DaysOfWeek;
myatinfo.Flags := Flags;
myatinfo.Command := PWideChar(mycommand);
pmyatinfo := @myatinfo;
Result := P(PWideChar(aMachine), pmyatinfo, @flag);
FreeLibrary(hLib);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
D: TDateTime;
aTime: DWORD;
begin
//시 분
aTime := (14 * 3600 + 52 * 60) * 1000;
NetScheduleJobAdd('', aTime, 0, 0, 1, 'calc.exe');
end;
end.