1. <tfoot id='2XnMK'></tfoot>

      <small id='2XnMK'></small><noframes id='2XnMK'>

        <bdo id='2XnMK'></bdo><ul id='2XnMK'></ul>
      <legend id='2XnMK'><style id='2XnMK'><dir id='2XnMK'><q id='2XnMK'></q></dir></style></legend>

      <i id='2XnMK'><tr id='2XnMK'><dt id='2XnMK'><q id='2XnMK'><span id='2XnMK'><b id='2XnMK'><form id='2XnMK'><ins id='2XnMK'></ins><ul id='2XnMK'></ul><sub id='2XnMK'></sub></form><legend id='2XnMK'></legend><bdo id='2XnMK'><pre id='2XnMK'><center id='2XnMK'></center></pre></bdo></b><th id='2XnMK'></th></span></q></dt></tr></i><div id='2XnMK'><tfoot id='2XnMK'></tfoot><dl id='2XnMK'><fieldset id='2XnMK'></fieldset></dl></div>

      在 Windows 任务计划程序中更改已计划任务的运行时间

      Changing run time of already scheduled tasks in windows task scheduler(在 Windows 任务计划程序中更改已计划任务的运行时间)

      <tfoot id='SwS19'></tfoot>

          <legend id='SwS19'><style id='SwS19'><dir id='SwS19'><q id='SwS19'></q></dir></style></legend>
        1. <i id='SwS19'><tr id='SwS19'><dt id='SwS19'><q id='SwS19'><span id='SwS19'><b id='SwS19'><form id='SwS19'><ins id='SwS19'></ins><ul id='SwS19'></ul><sub id='SwS19'></sub></form><legend id='SwS19'></legend><bdo id='SwS19'><pre id='SwS19'><center id='SwS19'></center></pre></bdo></b><th id='SwS19'></th></span></q></dt></tr></i><div id='SwS19'><tfoot id='SwS19'></tfoot><dl id='SwS19'><fieldset id='SwS19'></fieldset></dl></div>
            <tbody id='SwS19'></tbody>

              <small id='SwS19'></small><noframes id='SwS19'>

                <bdo id='SwS19'></bdo><ul id='SwS19'></ul>
                本文介绍了在 Windows 任务计划程序中更改已计划任务的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在修改机器上已存在的任务时遇到问题.我正在尝试使用从 C# 生成的互操作接口(从 system32/taskschd.dll 生成的 Interop.TaskScheduler.dll)来执行此操作.

                I have problem with modifying tasks which already exists on machine. I'm trying to do this with generated interop interfaces from C# (Interop.TaskScheduler.dll generated from system32/taskschd.dll).

                首先,我不能使用其他库,例如 http://taskscheduler.codeplex.com/.已经过测试,它可以与前面提到的库一起使用.现在,当我尝试对生成的接口做同样的事情时,没有任何变化.基本上我在做什么:

                To start with, I can't use other libraries like http://taskscheduler.codeplex.com/. Already tested and it works with library mentioned before. Now when I try do same with generated interfaces nothing changes. Basically what I'm doing:

                string STR_DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                string taskName = "taskName", 
                       user = "user", 
                       pass = "pass";
                
                DateTime nextRun = new DateTime.Now.AddDays(7);
                
                TaskSchedulerClass ts = new TaskSchedulerClass();
                ts.Connect(null, null, null, null);
                IRegisteredTask task = ts.GetFolder("\").GetTask(String.Format("\{0}",taskName));
                
                foreach (ITrigger t in task.Definition.Triggers)
                    t.StartBoundary = nextRun.ToString(STR_DateTimeFormat.Replace(" ", "T"));
                
                ts.GetFolder("\").RegisterTaskDefinition(task.Path, 
                                            task.Definition, 
                                            (int)_TASK_CREATION.TASK_UPDATE, 
                                            user, 
                                            pass, 
                                            _TASK_LOGON_TYPE.TASK_LOGON_PASSWORD, 
                                            null);
                

                乍一看它应该可以工作,但由于某种原因,当我尝试为在线运行分配新的日期时间时:

                For first look it should be working, but for some reason when I try to assign new datetime for run in line:

                t.StartBoundary = nextRun.ToString(STR_DateTimeFormat.Replace(" ", "T"));
                

                它不起作用.实际上,在那个 foreach 中它已经改变了,但是当我尝试调试并创建另一个打印 StartBoundary 值的 foreach 时,它显示了旧值.我做错了什么吗?有没有机会让它工作?:-) 谢谢.

                It doesn't work. Actually in that foreach it's changed but when I tried to debug and created another foreach which prints value of StartBoundary it shows old value. Am I doing something incorrect? Is there any chance to get it working? :-) Thank you.

                推荐答案

                如果您尝试像这样使用 Task Scheduler C# API 更新任务,则需要声明一个新的 ITaskDefinition.如果您尝试更改现有定义然后重新注册,则不起作用.

                If you are attempting to update a task using the Task Scheduler C# API like this, you need to declare a new ITaskDefinition. If you attempt to change the existing definition and then re-Register, it does not work.

                IRegisteredTask oldTask = ...
                ITaskDefinition task = oldTask.Definition;
                
                //modifications to oldTask.Definition / task
                
                //does **not** work
                folder.RegisterTaskDefinition(oldTask.Name, oldTask.Definition, ...
                //does work
                folder.RegisterTaskDefinition(oldTask.Name, task, ...
                

                答案归于原始海报,请参阅问题评论.我写了这个答案来澄清这个问题,并提请注意这个问题已经得到回答,因为类似的问题困扰了我几天.

                Answer credit goes to original poster, see comment on question. I wrote up this answer to clarify the issue, and draw attention to the fact that the question had been answered, as a similar issue troubled me for a few days.

                这篇关于在 Windows 任务计划程序中更改已计划任务的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                C# Attributes and their uses(C# 属性及其用途)
                C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
              • <i id='JEjZq'><tr id='JEjZq'><dt id='JEjZq'><q id='JEjZq'><span id='JEjZq'><b id='JEjZq'><form id='JEjZq'><ins id='JEjZq'></ins><ul id='JEjZq'></ul><sub id='JEjZq'></sub></form><legend id='JEjZq'></legend><bdo id='JEjZq'><pre id='JEjZq'><center id='JEjZq'></center></pre></bdo></b><th id='JEjZq'></th></span></q></dt></tr></i><div id='JEjZq'><tfoot id='JEjZq'></tfoot><dl id='JEjZq'><fieldset id='JEjZq'></fieldset></dl></div>

                    <tbody id='JEjZq'></tbody>
                  <tfoot id='JEjZq'></tfoot>

                  <small id='JEjZq'></small><noframes id='JEjZq'>

                    <legend id='JEjZq'><style id='JEjZq'><dir id='JEjZq'><q id='JEjZq'></q></dir></style></legend>
                      <bdo id='JEjZq'></bdo><ul id='JEjZq'></ul>