Solved

Starting WINNT 'AT' from within delphi

Posted on 1997-10-21
13
223 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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