本人最近写了一个程序需要定期执行,就想加到 任务计划中。但不是手动添加。
  各位高人  可否点一下。最好写个例字学习一下 。先谢谢了!!!

解决方案 »

  1.   

    type    
       TAT_INFO  =  record  
           JobTime:  DWord;  
           DaysOfMonth:  DWord;  
           DaysOfWeek:  UCHAR;  
           Flags:  UCHAR;  
           Command:  PWideChar;  
       end;  
     
       PAT_INFO  =  ^TAT_INFO;  
       NET_API_STATUS  =  LongInt;  
     
    (*//                        Zswang  
    NET_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;  
     
    interface  
     
    uses  
       Windows,  Messages,  SysUtils,  Classes,  Graphics,  Controls,  Forms,  Dialogs,  
       StdCtrls;  
     
    type  
       TAT_INFO  =  record  
           JobTime:  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;  
     
    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:=4294967295;  
       atinfo^.DaysOfWeek:=255;  
       atinfo^.command:='c:\showok.exe';  
       atinfo^.flags:=1;  
     
     
       if  NetScheduleJobAdd(nil,atinfo,jobid)  <  >2  then  
           showmessage('ok');  
       freemem(jobid);  
       freemem(atinfo);  
    end;  
     
    end.  
      

  2.   

    NetScheduleJobAdd
     只能用在服務器操作系統, 如win2003, win2000 server, winnt server