Solved

NT Scheduler

Posted on 1997-08-27
9
494 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 92
Simple Delphi Question 9 83
SUM 2 INTEGER ARRAYS INTO 1 10 93
JAudiorecorder record freezing the app 29 60
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

13 Experts available now in Live!

Get 1:1 Help Now