Solved

Starting WINNT 'AT' from within delphi

Posted on 1997-10-21
13
221 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

12 Experts available now in Live!

Get 1:1 Help Now