functions that start and stop in windows_task_scheduler?

patrick

Well-known member
Joined
Dec 5, 2021
Messages
263
Programming Experience
1-3
Hello

What are the functions that start and stop in windows_task_scheduler?
 
Please provide a FULL and CLEAR explanation of your problem. If I had to guess (which I do) then I'd say that you are probably using this NuGet package. I wasn't even aware that that existed until a few minutes ago but I found it with a web search, clicked the API documentation link and then followed a few more links to see that the Task class has Run and Stop methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.
 
Please provide a FULL and CLEAR explanation of your problem. If I had to guess (which I do) then I'd say that you are probably using this NuGet package. I wasn't even aware that that existed until a few minutes ago but I found it with a web search, clicked the API documentation link and then followed a few more links to see that the Task class has Run and Stop methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.



Thank YOU Very Much. Your answer last time was helpful. I wrote the code below with what you taught me.

Sample Code
C#:
using System;
using Microsoft.Win32.TaskScheduler;

class Program
{
   static void Main()
   {
      // Get the service on the remote machine
      using (TaskService ts = new TaskService(@"\\RemoteServer", "username", "domain", "password"))
      {
         // Create a new task definition and assign properties
         TaskDefinition td = ts.NewTask();
         td.RegistrationInfo.Description = "Does something";

         // Create a trigger that will fire the task at this time every other day
         td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

         // Create an action that will launch Notepad whenever the trigger fires
         td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));

         // Register the task in the root folder.
         // (Use the username here to ensure remote registration works.)
         ts.RootFolder.RegisterTaskDefinition(@"Test", td, TaskCreation.CreateOrUpdate, "username");
      }
   }
}


I want to Change only only the addition of arguments in the code.
(Becuase ... Already, the scheduler time, execution time interval, scheduler executable file exe path, etc. are registered in the Windows Task Scheduler UI.
So, in C# code, we only want to change the argument value.)
So, can I just modify the code like below?
Code that I modified to change the argument value using the sample code
C#:
using (TaskService ts = new TaskService())
            {
                string task = "Target scheduler";
                Task t = ts.FindTask(task);
                if (t != null)
                {
                    TaskDefinition td = ts.FindTask(task);
                    // Change argument values in scheduler
                    td.Actions.Add(new ExecAction("notepad.exe", "Argument", null));
                    ts.RootFolder.RegisterTaskDefinition("AppName", td, TaskCreation.CreateOrUpdate);
                }
            }
 
Last edited:
Please provide a FULL and CLEAR explanation of your problem. If I had to guess (which I do) then I'd say that you are probably using this NuGet package. I wasn't even aware that that existed until a few minutes ago but I found it with a web search, clicked the API documentation link and then followed a few more links to see that the Task class has Run and Stop methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.

Please teach me
 
So, can I just modify the code like below?
The documentation says that that's where commandline arguments go so presumably so. I can't tell you more than that because I've never used this library myself. As I said, I had no idea it even existed until I read this question. It's time for you to test it for yourself and see what happens. You don't need to ask us anything that you can test for yourself. Just create a console app that doesn't nothing but output its commandline arguments and then try creating a scheduled task to run it using code like that. If it works then you know it works and if it doesn't then you know it doesn't. Iterative testing like that is a fundamental part of software development.
 
Based on our OP's other threads (and his cross posts to other forums), what he really means by "teach me" is "gimme-the-codez".
 
If you want to learn then you need to understand how to work out what code you need to write for yourself and ask about specific issues along the way. I've told you what method to call. I assume that you've already learned how to call a method but you really ought to read the documentation for those methods anyway, to see if there are any parameters or what have you. You then need to get a Task object to call them on. Do you know how to do that? You added your Task to the RootFolder of your TaskService in the first place so logic dictates that you get it back from there, so read the documentation for that property. Etc. If you actually want to learn, you should be reading that documentation for yourself, unprompted, then asking us only about the specific parts you don't understand.
 
Back
Top Bottom