Solved

Starting WINNT 'AT' from within delphi

Posted on 1997-10-21
13
224 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 80
Is anyone willing to have a look through this code and help debug? 25 82
Dev express lookupcombo 3 34
RESTRequest Parameter 4 41
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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