用Delphi怎么调用windows的计划任务,添加一个计划呢?求助,在线等待

解决方案 »

  1.   

    :)
    去www.delphi-jedi.org把API Library中的TaskScheduler.zip下载下来研究研究
    里面包含了基本上所有关于系统计划任务的操作
      

  2.   

    我也是抄来的,不懂怎么样,你看看吧===
    ==================================
    如何调用Windows系统的计划任务程序?//示例添加任务typeTAT_INFO = recordJobTime: DWord;DaysOfMonth: DWord;DaysOfWeek: UCHAR;Flags: UCHAR;Command: PWideChar;end;PAT_INFO = ^TAT_INFO;NET_API_STATUS = LongInt;(*// ZswangNET_API_STATUS NetScheduleJobAdd(LPCWSTR Servername,LPBYTE Buffer,LPDWORD JobId);Windows NT/2000/XP: Included in Windows NT 3.1 and later.Windows 95/98/Me: Unsupported.//*)function NetScheduleJobAdd(ServerName: PWideChar; Buffer: PAT_INFO; var JobID: LongInt): NET_API_STATUS; external 'netapi32.dll' name 'NetScheduleJobAdd';unit insjob;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;typeTAT_INFO = recordJobTime: DWord;DaysOfMonth: DWord;DaysOfWeek: UCHAR;Flags: UCHAR;Command: PWideChar;end;
     
    PAT_INFO = ^TAT_INFO;NET_API_STATUS = LongInt;TForm1 = class(TForm)Button1: TButton;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end; function NetScheduleJobAdd(ServerName: PWideChar; Buffer: PAT_INFO; var JobID: PDWord): NET_API_STATUS;stdcall;
    varForm1: TForm1;implementation{$R *.DFM}function NetScheduleJobAdd; external 'netapi32.dll' name 'NetScheduleJobAdd';procedure TForm1.Button1Click(Sender: TObject);varATInfo:PAT_Info;jobid:PDword;begingetmem(atinfo,sizeof(TAt_info));getmem(jobid,sizeof(dword));atinfo^.jobtime:=3*60*60*1000+15*60*1000;//miliseconds from midnight to 3:15atinfo^.DaysOfMonth:=4294967295;atinfo^.DaysOfWeek:=255;atinfo^.command:='c:.exe';atinfo^.flags:=1; 
    if NetScheduleJobAdd(nil,atinfo,jobid) < >2 thenshowmessage('ok');freemem(jobid);freemem(atinfo);end;end.
     
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ADODB, StdCtrls;
    type
     TAT_INFO = record
       JobTime: DWord;
       DaysOfMonth: DWord;
       DaysOfWeek: UCHAR;
       Flags: UCHAR;
       Command: PWideChar;
     end; PAT_INFO = ^TAT_INFO;
     NET_API_STATUS = LongInt;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     function NetScheduleJobAdd(ServerName: PWideChar; Buffer: PAT_INFO; var JobID: PDWord): NET_API_STATUS;stdcall;
    var
      Form1: TForm1;implementation{$R *.dfm}
    function NetScheduleJobAdd; external 'netapi32.dll' name 'NetScheduleJobAdd';
    procedure TForm1.Button1Click(Sender: TObject);
    var
     ATInfo:PAT_Info;
     jobid:PDword;
    begin
     getmem(atinfo,sizeof(TAt_info));
     getmem(jobid,sizeof(dword));
     atinfo^.jobtime:=3*60*60*1000+15*60*1000;//miliseconds from midnight to 3:15
     atinfo^.DaysOfMonth:=12;
     atinfo^.DaysOfWeek:=7;
     atinfo^.command:='c:\showok.exe';
     atinfo^.flags:=$1;
     if NetScheduleJobAdd(nil,atinfo,jobid)<>no_error then
       showmessage('ok');
    end;
    end.