简体   繁体   English

Windows Task Scheduler安装程序

[英]Windows Task Scheduler Installer

I have a little .exe written in c# .net that I want to run on the server every 24 hours. 我有一个用C#.net编写的小.exe文件,我希望每24小时在服务器上运行一次。 So naturally I would just use the Windows Task Schedular rather then doing the math myself. 因此,我自然会只使用Windows Task Schedular而不是自己做数学。 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? 有没有办法像Visual Studio设置项目那样呢? If not is there like a powershell / batch script that could be used to run after installation? 如果没有的话,可以在安装后运行Powershell /批处理脚本吗?

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. 您可以使用Powershell脚本或批处理文件来执行schtasks ,它是任务计划程序的命令行界面。

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. 还有一个托管包装器 ,允许您使用C#创建计划任务。

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 您可以使用以下命令在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. 这将循环浏览文本文件中的服务器列表(每行1个服务器),并使用psexec在每个服务器上调用schtasks并安装任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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