Starting WINNT 'AT' from within delphi

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 ?
jvh042097Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

Pegasus100397Commented:
Jvh,

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

Good luck with your project!
Pegasus
0
mirek071497Commented:
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
Pegasus100397Commented:
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
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jvh042097Author Commented:
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
mirek071497Commented:
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
jvh042097Author Commented:
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
Pegasus100397Commented:
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
jvh042097Author Commented:
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
mirek071497Commented:
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
mirek071497Commented:
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
jvh042097Author Commented:
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
mirek071497Commented:
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
mirek071497Commented:
Hi
Do you try this ? I have now NT so I can help more, but mayby you don't need more.
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
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.