NT Service ?

How do i write a program that runs as a NT Service ?

Basically i want to achieve this :
I want to invoke a carry out a certain activity (liking invoking a certain application) based on time. That is, i schedule some activities for some time in future. Now, my appln. should continuosly check for time and if it is time to carry out that activity, simply do that, and continue running.

I guess, i must write a program that runs in background as a Service. But, should not be too heavy weight or hog resources.

What language has to be used...VC++ ?

How do i do this ?
Any available code ...
or info. on where i can find help on this would be helpful.


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

You could write a service that does what you want, but on NT the simpler way to accomplish this would be to use the AT command to run your program.  

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.

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
JituAuthor Commented:
I want to schedule the tasks thru my program. I can do this by running the AT command everytime i want to do this, in the command window via my program.

But, is there a way, whereby i can access information about already scheduled tasks (How many etc...).
Or change or delete them thru my program ?

The information about what is already scheduled can be obtained from the registry.  Look at
You should be able to obtain the information you need from the sub keys to tell about the scheduled tasks.  Then you can manipulate the registry, or use the AT command (/delete etc) with a winexec to manipulate it for you.
JituAuthor Commented:
Thanks Francis. I am looking into this.

But, modifying Registry values like this from what i understand is actually dangerous and not recommended.
May be i could read from the registry and modify it using the AT /delete command. Cumbersome though.

So, i am thinking whether i shud write my own appln. which runs as a service and does the job for me or use the way suggested by u.
The other thing that you can do is take an EXE that you create and run the SRVINSTW.exe which you can find on the Windows NT Re3source kit.  Te wizard will walk you through setting up a program as a service.
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

From novice to tech pro — start learning today.