6

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 Schedular rather then doing the math myself. I have created the program, but I would like to create an installer that just set everything up. Is there a way to do this with like the Visual Studio set-up projects? If not is there like a powershell / batch script that could be used to run after installation?

Bottom Line: Automate the creation of the task.

Nate
  • 12,963
  • 4
  • 59
  • 80
Brad Semrad
  • 1,501
  • 1
  • 11
  • 19

2 Answers2

5

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

Then you simply need to run the script in order to setup the scheduled task.

There is also a managed wrapper that allows you to create schedules tasks in C#, if you would rather go that way.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

I know this is an old question, but I figure this may help someone else:

You can use the following to run in cmd.exe

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 loop through the list of servers in a text file (1 server per line) and use psexec to call schtasks on each server and install your task.

crunchy
  • 246
  • 1
  • 3
  • 12