Windows Task Scheduler Installer

I have a little .exe written in C # .net that I want to run on the server every 24 hours. So naturally, I would just use the Windows task manager, and then do the math myself. I created a program, but I would like to create an installer that just installed everything. Is there a way to do this, as in Visual Studio projects? If not, what about a powershell / batch script that can be used to run after installation?

Bottom Line: Automate task creation.

+4
source share
3 answers

You can use the powershell script file or batch file to execute schtasks , which is the command line interface for the task scheduler.

Then you just need to run the script to set up the scheduled task.

There is also a managed wrapper that allows you to create schedule tasks in C # if you prefer to go this way.

+4
source

I do not believe that the installer out of the box can do this for you, but there is a shell for the task scheduler and a good example of how to use it here:

Creating Scheduled Tasks

You can either compile this into a new EXE, which starts after the installation is complete.

+1
source

I know this is an old question, but I suppose it might help someone else:

To work in cmd.exe you can use the following command

 FOR /F %1 IN ("path to text file containing list of servers") do psexec.exe \\%1 -u "username to execute schtasks under" -p "password" schtasks /Create /S %1 /RU "username that will run the task" /RP "password" /XML "xml file of the task to install" /TN "name of the task" 

This will go through the list of servers in a text file (1 server per line) and use psexec to call schtasks on each server and set your task.

0
source

Source: https://habr.com/ru/post/1394695/


All Articles