Solved

NT Scheduler

Posted on 1997-08-27
9
490 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.
0
Comment
Question by:CFantin
  • 6
  • 3
9 Comments
 
LVL 3

Accepted Solution

by:
mirek071497 earned 150 total points
ID: 1342579
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
 
LVL 1

Author Comment

by:CFantin
ID: 1342580
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342581
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342582
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:CFantin
ID: 1342583
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342584
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342585
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342586
Sorry for my english i bad understand you'r last comment.
0
 
LVL 1

Author Comment

by:CFantin
ID: 1342587
Thanks a lot!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now