用Delphi怎么调用windows的计划任务,添加一个计划呢?求助,在线等待
解决方案 »
- 怎么在 dbgrid 中取出某一列的最大值, 不能用SQL语句来做
- delphi下有什么方法不安装oracle客户端可以连接oracle的?
- TCP传输协议问题
- 关于多线程中如何传递参数?
- 如何将delphi的Tobject对象传递给VB写的ActiveX Dll
- 数据库数据删除问题。再线等,速结贴。
- 怎样把DBGrid当前显示的记录打印出来!?也有可能是查询后的结果!
- 分
- **** 讨论:各地的“乐敦”眼药水多少钱?*****
- 又有50分要送出~~能否给出一个包含TDBedit(字段类型是日期型)、Tdbcheckbox(字段类型是数值型)、Tdbcombobox(字段类型是数值型)、Tradiongroup等例子,详细有分喽
- 将Delphi扩展成用户类型的设计器,高手们讨论讨论。
- 想用DBchart显示一个表
去www.delphi-jedi.org把API Library中的TaskScheduler.zip下载下来研究研究
里面包含了基本上所有关于系统计划任务的操作
==================================
如何调用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.
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.