简体   繁体   English

使用C#启动时使用计划任务启动程序吗?

[英]Start program with a Scheduled Task on startup with C#?

I must make a new Scheduled Task to start an application on windows startup. 我必须执行新的计划任务才能在Windows启动时启动应用程序。
Just like placing it in the "Startup" folder... 就像将其放在“启动”文件夹中一样...
But I need to create, enable and disable this task in C#. 但是我需要在C#中创建,启用和禁用此任务。
How do I do this? 我该怎么做呢?

There is a Task Scheduler library available on codeproject.com that might do what you need: http://www.codeproject.com/KB/cs/tsnewlib.aspx 在codeproject.com上有一个Task Scheduler库可以满足您的需要: http : //www.codeproject.com/KB/cs/tsnewlib.aspx

Its an older library that may or may not work with newer versions of windows. 它是一个较旧的库,可能会或可能不会与较新版本的Windows一起使用。 At the very least, it should point you in the right direction. 至少,它应该为您指明正确的方向。

I would recommend doing this as a windows service. 我建议将其作为Windows服务进行。 It gives you the most control over the life cycle of a task like this. 它使您可以最大程度地控制此类任务的生命周期。 Here is a detailed tutorial. 这是详细的教程。 There is also a great wizard in Visual Studio to get you going in a few minutes. Visual Studio中还有一个很棒的向导,可以帮助您在几分钟内完成操作。

I usually like to create a debug service using the sc tool (see tutorial) that points directly to your debug object as a means of easy debugging. 我通常喜欢使用sc工具(请参阅教程)创建调试服务,该工具直接指向您的调试对象,以方便调试。

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

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