Namespace for Microsoft.Win32.TaskScheduler

MiPakTeh 1,476 Reputation points
2021-07-30T11:30:30.72+00:00

Hi All,

To find refference for namespace using Microsoft.Win32.TaskScheduler;. Many link in internet but when Install or copy ,It nothing happen.It still not functioning.

I try learning how to run program at winlogon.Can somebody give a simple example.

Thank.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32.TaskScheduler;

namespace Hkey__Testing
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Get the service on the local machine
            using (TaskService ts = new TaskService())
            {
                // 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
                ts.RootFolder.RegisterTaskDefinition(@"Test", td);

                // Remove the task we just created
                ts.RootFolder.DeleteTask("Test");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Alberto Poblacion 1,571 Reputation points
    2021-07-31T06:19:33.707+00:00

    You need to download the corresponding Microsoft.Win32.TaskScheduler DLL and then add a Reference to it from the project References.

    One easy way to accomplish this is by using the NuGet package:

    https://www.nuget.org/packages/TaskScheduler

    Adding the package will provide the DLL and also add the Reference.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 90,681 Reputation points
    2021-07-30T11:51:44.307+00:00

    You can see and modify the sample I had posted in this thread : Task scheduler by using Microsoft.Win32.TaskScheduler.dll


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.