怎么用delphi程序添加window的计划任务(NetScheduleJobAdd参数怎么传都有问题)(100分)

  • 主题发起人 主题发起人 stephens
  • 开始时间 开始时间
S

stephens

Unregistered / Unconfirmed
GUEST, unregistred user!
不知怎么着,我怎么传参数返回值都是123,返回是0才成功呀,谁能告诉我这些参数的具体意思!最好能copy一段写好的小程序<br>type<br>&nbsp; TAT_INFO = record<br>&nbsp; JobTime: DWord;<br>&nbsp; DaysOfMonth: DWord;<br>&nbsp; DaysOfWeek: UCHAR;<br>&nbsp; Flags: UCHAR;<br>&nbsp; Command: PWideChar;<br>end;<br><br>PAT_INFO = ^TAT_INFO;<br>NET_API_STATUS = LongInt;<br>function NetScheduleJobAdd(ServerName: PWideChar; Buffer: PAT_INFO; var JobID: LongInt): NET_API_STATUS; external 'netapi32.dll' name 'NetScheduleJobAdd';
 
function NetScheduleJobAdd ( Servername : LPWSTR; PtToBuffer : Pointer; JOBID : LPDWORD ) : DWORD;<br><br>implementation<br><br>const<br>&nbsp;netapi32 = 'netapi32.dll';<br><br>function NetScheduleJobAdd; &nbsp;external netapi32 name 'NetScheduleJobAdd';<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>const JOB_RUN_PERIODICALLY = 4; { this value must be corrected !!!!! }<br>var<br>&nbsp;Buffer : ^AT_INFO;<br>&nbsp;JobID : DWORD;<br>begin<br>&nbsp;New(Buffer);<br>&nbsp;Buffer^.JobTime := DateTimeToTimeStamp(Now).Time;<br>&nbsp;Buffer^.DaysOfMonth := 0;<br>&nbsp;Buffer^.DaysOfWeek := 127;<br>&nbsp;Buffer^.Flags := JOB_RUN_PERIODICALLY;<br>&nbsp;Buffer^.Command := 'your command';<br>&nbsp;NetScheduleJobAdd( 'HURICANE', @Buffer, @JobID );<br>&nbsp;Dispose( Buffer);<br>end;<br>
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp;StdCtrls;<br><br><br>type<br>&nbsp; &nbsp; Pat_info= ^at_info;<br>&nbsp; &nbsp; at_info = record<br>&nbsp; &nbsp; &nbsp; JobTime:DWORD;<br>&nbsp; &nbsp; &nbsp; DaysOfMonth:DWORD;<br>&nbsp; &nbsp; &nbsp; DaysOfWeek:UCHAR;<br>&nbsp; &nbsp; &nbsp; Flags:UCHAR;<br>&nbsp; &nbsp; &nbsp; Command:LPWSTR;<br>&nbsp;end;<br>type<br>&nbsp;TForm1 = class(TForm)<br>&nbsp; &nbsp;Button1: TButton;<br>&nbsp; &nbsp;Button2: TButton;<br>&nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br>&nbsp;private<br>&nbsp; &nbsp;{ Private declarations }<br>&nbsp;public<br>&nbsp; &nbsp;{ Public declarations }<br>&nbsp;end;<br>const<br>&nbsp;JOB_RUN_PERIODICALLY = $01; { in-/output flag }<br>&nbsp;JOB_EXEC_ERROR = $02; { output flag }<br>&nbsp;JOB_RUNS_TODAY = $04; { output flag }<br>&nbsp;JOB_ADD_CURRENT_DATE = $08; { input flag }<br>&nbsp;JOB_NONINTERACTIVE = $10; { in-/output flag }<br><br><br>var<br>&nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function NetScheduleJobAdd(<br>&nbsp;aMachine:string; // empty string for local machine<br>&nbsp;aTime: DWORD; // millisec. from midnight<br>&nbsp;DaysOfMonth: DWORD; //bit 0: 1. day bit1: 2. day value=0: not assigned<br>&nbsp;DaysOfWeek: byte; //bit 0: Monday .... value=0: not assigned<br>&nbsp;Flags: byte; //<br>//JOB_RUN_PERIODICALLY<br>//If this flag bit is set, the job runs on every day for which corresponding<br>///bits in DaysOfMonth or DaysOfWeek are set. If this flag bit is clear, then<br>//job runs only once for each bit that was set in DaysOfMonth or DaysOfWeek at<br>//the time of job submission.<br>//JOB_ADD_CURRENT_DATE<br>//When this flag bit is set, the job will also execute at the first<br>//occurrence of JobTime at the computer to which the job is submitted. In<br>//other words, setting this flag bit is equivalent to setting the<br>//corresponding day bit in the DaysOfMonth bitmask.<br>&nbsp;mycommand: Widestring ):DWORD;<br>// Result: Win32Error<br>var hLib : THandle;<br>&nbsp; &nbsp;Flag : DWord;<br>&nbsp; &nbsp;Ergebnis : DWord;<br>&nbsp; &nbsp;P : function (Servername:LPCWSTR;Buffer:Pat_info;JobId:LPDWORD ): DWord;<br>stdcall; // NetScheduleJobAdd<br>&nbsp; &nbsp;myatinfo: at_info;<br>&nbsp; &nbsp;pmyatinfo: pat_info;<br>begin<br>&nbsp; P := nil;<br>&nbsp; hLib := LoadLibrary('NETAPI32.DLL');<br>&nbsp; P := GetProcAddress(hLib,'NetScheduleJobAdd');<br><br>&nbsp; myatinfo.JobTime:=aTime;<br>&nbsp; myatinfo.DaysOfMonth:=DaysOfMonth;<br>&nbsp; myatinfo.DaysOfWeek:=DaysOfWeek;<br>&nbsp; myatinfo.Flags:=Flags;<br>&nbsp; myatinfo.Command:=PWideChar(mycommand);<br><br>&nbsp; pmyatinfo:=@myatinfo;<br>&nbsp; Result := P(PWideChar(aMachine),pmyatinfo,@flag);<br><br>&nbsp; FreeLibrary(hLib);<br>end;<br><br><br><br>{function NetScheduleJobGetInfo(<br>&nbsp;aMachine:string; // empty string for local machine<br>&nbsp;JobID : dword;<br>&nbsp;Myflg : byte) : dword; //<br>//JOB_RUN_PERIODICALLY<br>//If this flag bit is set, the job runs on every day for which corresponding<br>///bits in DaysOfMonth or DaysOfWeek are set. If this flag bit is clear, then<br>//job runs only once for each bit that was set in DaysOfMonth or DaysOfWeek at<br>//the time of job submission.<br>//JOB_ADD_CURRENT_DATE<br>//When this flag bit is set, the job will also execute at the first<br>//occurrence of JobTime at the computer to which the job is submitted. In<br>//other words, setting this flag bit is equivalent to setting the<br>//corresponding day bit in the DaysOfMonth bitmask.<br>// Result: Win32Error<br>var hLib : THandle;<br>&nbsp; &nbsp;Flag : DWord;<br>&nbsp; &nbsp;Ergebnis : DWord;<br>&nbsp; &nbsp;P : procedure (Servername:LPCWSTR;JobId:DWORD;Buffer:Pat_info);<br>stdcall; // NetScheduleJobAdd<br>&nbsp; &nbsp;myatinfo: Pat_info;<br>&nbsp; &nbsp;pmyatinfo: pat_info;<br>begin<br>&nbsp; P := nil;<br>&nbsp; hLib := LoadLibrary('NETAPI32.DLL');<br>&nbsp; P := GetProcAddress(hLib,'NetScheduleJobGetInfo');<br><br>&nbsp; myatinfo.Flags:=MyFlg;<br><br>&nbsp; pmyatinfo:=@myatinfo;<br>&nbsp; Result := P(PWideChar(aMachine),JOBID,myatinfo);<br><br>&nbsp; FreeLibrary(hLib);<br>end;}<br><br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>NetScheduleJobAdd('',54000000,0,0,1, 'c:/project1.exe');<br>//showmessage((NetScheduleJobGetInfo('',1,JOB_RUN_PERIODICALLY)));<br><br>end;<br><br>end.
 
接受答案了.
 
后退
顶部