Application as Service - How to launch the service at the certain time or date?

One of the advantages of Windows services is the fact that you may launch them automatically at the certain time of the day or on the specific date. This is particularly useful if you want to run CPU/RAM/HDD access consuming application (backup for instance) at the time when it will not affect other users.

You may start the service at the certain time using graphical user interface or command line options. Whichever method you choose you should be able to run it without any problems, however we recommend using GUI until you get more experience.

1. Start the service graphical user interface



2. Start the service at the specific time/date using command line


c:\Program Files\Eltima Software\Application as Service\app2srv.exe INSTALL /SN="Notepad" /PM="C:\WINDOWS\System32\notepad.exe" /SCD="13:00:00|||||D127" /SCD="||14:00:00|||D127"

SN (Service Name) and PM (Executable file) parameters are mandatory. SCD (schedule) is the key which, actually, defines the schedule date when your application will be launched or stopped. Its value is a string of parameters one after another separated by vertical line:

Start time from

This is a 24-hour formatted time string that defines the start time of your application. For instance, 13:00:00 means that your application which is launched as service might be started at 1 PM local time (command line example: /SCD="16:48:00|||||D127" means that application will be launched at 4:48 PM every day).

Start time to

This is a 24-hour formatted time string that is active when "Start time from" parameter is used only and defines the end time, in other words, your application might start till that time (command line example: /SCD="16:48:00|17:00:00||||D127" means that application might be launched from 4:48 PM to 5 PM every day).

Stop time

This is a 24-hour formatted time string that defines the stop time of your application which is launched as service. For instance, 14:00:00 means that application should be stopped at 2 PM local time. Note, that you are not allowed to use "Stop time" option in the same SCD key if you used "Start time from ... to ..." parameters already. In other words, in order to use "Stop time" parameter, please, create new SCD key. (For example, you want your application to be launched at 1 PM and stopped 2 PM everyday, schedule parameter should be the following: /SCD="13:00:00|||||D127" /SCD="||14:00:00|||D127", the wrong is: /SCD="13:00:00||14:00:00|||D127"

Start anytime

This option starts application anytime according to time condition.
Note, that "Start anytime" option should be used along with certain date, week day or day of month.

Periodically

This option defines time when your application which is launched as service might be started or stopped from one date to another (command line example: /SCD="16:48:00|||28.02.2008|29.02.2008|D127" means that application might be launched at 4:48 PM everyday between February 28 and February 29).

Daily

This option defines whether your application which is launched as service should start or stop on certain days of the week. By default, the application is allowed to run on any day of the week. The resulting string should consist of the sum of the weekdays, preceded by letter "D". Weekday's values are the power of two starting from Monday. I.e. Monday equals 1, Tuesday equals 2, Wednesday equals 4, Thursday equals 8, Friday - 16, Saturday - 32 and Sunday - 64. For instance, if you want your service running on daily basis then the resulting string is D127 (command line example: /SCD="16:48:00|||||D3" means that application will be launched at 4:48 PM on Monday and Tuesday).

Monthly

This option that defines whether application which is launched as service should start or stop monthly between several days or on certain day. In case you would like to run or stop it on particular day of the month or monthly basis then you should specify the number of month's day (or the range of the days) preceded by letter "M". For example, if you want to run your application on 3rd day of the each month then you should construct M3 string. M10-20 string means that your application should be launched or stopped between 10th and 20th days of the month (command line example: /SCD="16:48:00|||||M10" means that application will be launched at 4:48 PM on 10 day of every month).

Please, note that your application will run in background unless you provide the /ID1 parameter ("Interaction with desktop" enabled) and set "Account" to "LocalSystem" (which is default parameter and therefore, could be omitted).

c:\Program Files\Eltima Software\Application as Service\app2srv.exe START /SN=Notepad


Please, note, that if you have several items in your schedule (for example, start time at 17:00, stop time at 18:00, start time at 19:00 and stop time at 20:00) you should select "Restart the program after" option at Advanced tab if you want your schedule to be executed properly.