We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

NT Scheduler

CFantin
CFantin asked
on
Medium Priority
542 Views
Last Modified: 2008-02-26
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.
Comment
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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!!!
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.
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.

Author

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.
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
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;

Sorry for my english i bad understand you'r last comment.

Author

Commented:
Thanks a lot!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.