Solved

Starting WINNT 'AT' from within delphi

Posted on 1997-10-21
13
222 Views
Last Modified: 2010-04-04
Using ExecuteFile, i can start up whatever application from withing Delphi.

How can I execute the NT's 'AT'-command (with parameters) from within delphi so as to be able to schedule the execution of a certain app ?
0
Comment
Question by:jvh042097
  • 6
  • 4
  • 3
13 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1348466
Jvh,

Have you tried to use the WinExec (old) or CreateProcess (new) API functions? :)

Good luck with your project!
Pegasus
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1348467
No !
You must use NetScheduleJobAdd and others functions. You can find this in help. (NetScheduleJobEnum). Some weeks ago I was answering the question about this. Please find this in PAQ.
0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1348468
Jvh,

My error, Mirek is correct. Use the NetScheduleJobAdd (and related) to handle your request. Dis-allow my answer and award mirek the points if this works for you :)

regards
Pegasus
0
 

Author Comment

by:jvh042097
ID: 1348469
The answer was totally wrong. Sorry for mirek, but i couldn't give him the points he deserved. I did however open his previous answer on the AT-problem, which will probably give him 15 points bonus !

Thanks anyway for your time and energy Pegasus and Mirek !
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1348470
Hi
When you open question in PAQ i don'rt receiving any points. No problem, I will try to help not to get points.
If you need some help than I can give you this.
My english is rather poor so I don't understand if you need more help. If you need then ask.
I am sure so You need NetScheduleJobAdd, because this is api call to scheduling system in NT. AT is a command which use the same functions.

Regards
Mirek
0
 

Author Comment

by:jvh042097
ID: 1348471
Mirek, i still have problems in getting the NetScheduleJobAdd thing working fine. Exception errors and things like that. Can you give me please a good working example of this function to start up let us say clock.exe every working day at 02:00 AM.

Many thanks
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 3

Expert Comment

by:Pegasus100397
ID: 1348472
Jvh,

Until you get the NetScheduleJobAdd API thingy working might I suggest a (very kludgy) workaround?

Write the AT commands + parameters to a text file as a .BAT and WinExec or CreateProcess the .BAT file? Same way of doing the same thing although very kludgy from a programmer's standpoint. Might at least get you moving again until you get the API calls figured out (I'm using Win95 here so no AT command available to help ya out)

Just a thought to help a fellow programmer in a pinch :)
Pegasus
0
 

Author Comment

by:jvh042097
ID: 1348473
I already solved it via an ExecuteFile procedure which in fact calls the win api to start an app. I found the AT.EXE in the winnt35\system32; before i thought it was an internal command.
BUT : i still like to see a working example of the NetScheduleJobAdd thing, because my trial gave an exception error somewhere.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1348474
I can't understand so pleace somment me.

You read  question : qid=8630015389 (which is with examples) and this not working, or you missunderstand some, or you can't pay additional 15pt.

If you can't pay 15pt then here is this example. This example is for Enum of jobs, however I think so you can create add with the same method.

unit Unit1;

{$A+,Z+}

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    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);
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;

end.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1348475
Of course HURICANE is the name of my Server. You must change to your server name.

Description of AT structures and functions is in help.
0
 

Author Comment

by:jvh042097
ID: 1348476
mirek, this example i had already bought. But when i try to adapt it for 'JobAdd', i get execption error, probably caused by wrong pointers or something. So i was asking for a working example of JobAdd, not Enum ....
THANKS !
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1348477
Unfortunatelly I have not now SDK and access to WinNT so I cann't test this code, but maby this can help you some.

Before you start use this create job with AT and read this with Your program to retrive the value for constans JOB_RUN_PERIODICALLY

  function NetScheduleJobAdd ( Servername : LPWSTR; PtToBuffer : Pointer; JOBID : LPDWORD ) : DWORD;

implementation

const
  netapi32 = 'netapi32.dll';

function NetScheduleJobAdd;  external netapi32 name 'NetScheduleJobAdd';

procedure TForm1.Button2Click(Sender: TObject);
const JOB_RUN_PERIODICALLY = 4; { this value must be corrected !!!!! }
var
  Buffer : ^AT_INFO;
  JobID : DWORD;
begin
  New(Buffer);
  Buffer^.JobTime := DateTimeToTimeStamp(Now).Time;
  Buffer^.DaysOfMonth := 0;
  Buffer^.DaysOfWeek := 127;
  Buffer^.Flags := JOB_RUN_PERIODICALLY;
  Buffer^.Command := 'your command';
  NetScheduleJobAdd( 'HURICANE', @Buffer, @JobID );
  Dispose( Buffer);
end;

0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 150 total points
ID: 1348478
Hi
Do you try this ? I have now NT so I can help more, but mayby you don't need more.
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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now