• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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.

Thx.

0
Jitu
Asked:
Jitu
  • 3
  • 2
1 Solution
 
bfrancisCommented:
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
                   command.
/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.
0
 
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 ?

0
 
bfrancisCommented:
The information about what is already scheduled can be obtained from the registry.  Look at
HKEY_LOCAL_MACHINE\system\currentcontrolset\services\schedule
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.
0
 
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.
0
 
bfrancisCommented:
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.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now