NT Scheduler

I want to write an applicastion that will link into the NT Scheduler API calls. I have found the API calls (NetSchuduleJobAdd, NetScheduleJobDel, NetScheduleJobEnum, NetScheduleJobGetInfo), but they are not defined in any of the delphi source files and this makes them un-usable without having to declare them externaly myself.

The structures used by the functions are not defined anywhere and I know that from past experience you cannot just declare them in delphi and pass them to the functions.

I am using Delphi 3.

Any help on this problem will be appreciated.
LVL 1
CFantinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mirek071497Commented:
probably you need AT structure :

typedef struct _AT_INFO {
      DWORD      JobTime;
      DWORD      DaysOfMonth;
      UCHAR      DaysOfWeek;
      UCHAR      Flags;
      LPWSTR      Command;
} AT_INFO, *PAT_INFO, *LPAT_INFO;

typedef struct _AT_ENUM {
      DWORD      JobId;
      DWORD      JobTime;
      DWORD      DaysOfMonth;
      UCHAR      DaysOfWeek;
      UCHAR      Flags;
      LPWSTR      Command;
} AT_ENUM, *PAT_ENUM, *LPAT_ENUM;

JobId      -Job identifier of an already submitted job.
JobTime    -Time of day when a job is scheduled to run.
            Time is a local time at a computer where Schedule service
            is running. Time is measured from midnight
            and is expressed in milliseconds.
DaysOfMonth-Bitmask for days of month when a job is scheduled
            to run. The bitmask is NULL if a job was scheduled
            to run only once at the first occurrence of JobTime.
            For each bit that is set in the bitmask a job
            will run at JobTime on a corresponding day of the month.
            Bit 0 corresponds to first day of the month, etc.
DaysOfWeek -Bitmask for days of week when this job is scheduled to run.
            The bitmask is NULL if a job was scheduled to run only once
            at the first occurrence of JobTime.
            For each bit that is set in the bitmask a job will run
            at JobTime on a corresponding day of the week.
            Bit 0 corresponds to Monday (first day of the week), etc.
Flags      -Bitmask describing job properties.
            For job submission (NetScheduleJobAdd) possible values are:
            JOB_RUN_PERIODICALLY
              If this flag bit is set then job runs on every day
              where corresponding bits in DaysOfMonth or DaysOfWeek
              are set. If this flag bit is clear then job runs
              only once for each bit that was set in DaysOfMonth
              and/or DaysOfWeek at the time of job submission.
            JOB_ADD_CURRENT_DATE
              When this flag bit is set then job will also execute
              at the first occurrence of JobTime at the computer
              where job is submitted to. In other words,
              setting this flag bit is equivalent to setting
              the corresponding day bit in DaysOfMonth bitmask.

            For job information retrieval
              (NetScheduleJobEnum and NetScheduleJobGetInfo) possible
              values are:
              JOB_RUN_PERIODICALLY
                This flag bit is equal to the original value
                of this flag bit when a job was submitted.
              JOB_EXEC_ERROR
                This flag bit is set whenever Schedule service
                failed to execute successfully this job
                the last time this job was supposed to run.
              JOB_RUNS_TODAY
                This flag bit is set if JobId is larger
                than the current time of day at the computer
                where this job is queued at.
Command     -Points to a Unicode string that contains the name
             of command, batch program or binary file to execute.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CFantinAuthor Commented:
I have read the help!!!!!!!!!

But the api functions are not included in the Delphi functions list
and cannot be used from delphi.
The functions are in a libruary netapi32.lib I want to know how to access these functions not the text from the help file!!!
0
mirek071497Commented:
Sorry, but english is very poor, but you realy ask for this. I write this for you tomorrow because in my country is now night.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

mirek071497Commented:
OK. here is example for you :

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
  end;


  AT_ENUM = Record
    JobId       : DWORD;
    JobTime     : DWORD;
    DaysOfMonth : DWORD;
    DaysOfWeek  : UCHAR;
    Flags       : UCHAR;
    Command     : LPWSTR;
  end;

  function NetScheduleJobEnum( Servername : LPWSTR; PointerToBuffer : Pointer;
                               PreferredMaximumLength : DWORD;
                               EntriesRead, TotalEntries, ResumeHandle :  LPDWORD ) : DWORD; stdcall;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const
  netapi32 = 'netapi32.dll';

function NetScheduleJobEnum; external netapi32 name 'NetScheduleJobEnum';


procedure TForm1.Button1Click(Sender: TObject);
var
  Result : DWORD;
  Buffer : Array[0..10] of AT_ENUM;
  MaxLen : DWORD;
  EntriesRead,
  TotalEntries,
  ResumeHandle : DWORD;
begin
  MaxLen := SizeOf( Buffer );
  ResumeHandle := 0;
  Result := NetScheduleJobEnum( 'HURICANE', @Buffer, MaxLen, @EntriesRead, @TotalEntries, @ResumeHandle );
  ShowMessage( 'Entries Readed='+IntToStr(EntriesRead) );
  ShowMessage( 'Total Entries='+IntToStr(TotalEntries) );
end;

end.
0
CFantinAuthor Commented:
Thanks for the Example.

I have the Add and delete woking but I cannot get the ENum and GetInfo functions to to work.

If you could give an example where you get all of the scheduled items and display the command for each I will gladly give you an A.
0
mirek071497Commented:
Hi CFantin!

1.No problem but you'r question is now modified. I can answer this but not for 150pt.
2.I write all what you need to write working program.
3.If you have not time to write this i can write but more points is needed.
4.If you can do add and delete later then why you don't write this at you'r question.

Regards
Mirek
0
mirek071497Commented:
No more points ?
OK here is example.

procedure TForm1.Button1Click(Sender: TObject);
type TestBuf = array[0..3] of AT_ENUM;
var
  Buffer : ^TestBuf;
  i, MaxLen, Result, EntriesRead, TotalEntries, ResumeHandle : DWORD;
begin
  MaxLen := SizeOf( TestBuf );
  ResumeHandle := 0;
  Memo1.Lines.Clear;
  repeat
    Result := NetScheduleJobEnum( 'HURICANE', @Buffer, MaxLen, @EntriesRead, @TotalEntries, @ResumeHandle );
    for i:=0 to EntriesRead-1 do
      Memo1.Lines.Add('JobID='+IntToSTr(Buffer[i].JobId)+' command='+WideCharToString(Buffer[i].Command) );
  until TotalEntries=EntriesRead;
end;

0
mirek071497Commented:
Sorry for my english i bad understand you'r last comment.
0
CFantinAuthor Commented:
Thanks a lot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.