简体   繁体   中英

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 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM