Scheduled Tasks in Windows

Hi,

I want to be able to disable / enable my windows scheduled tasks by code.

How can i do it



Answer this question

Scheduled Tasks in Windows

  • RonaldLaeremans

    You can stop or start windows scheduled, starting or stopping windows service associate to it, the code to do it.

    The first add System.ServiceProcess to project references, the code are this:

    using System.ServiceProcess;

    int i;

    ServiceController[] servicios;

    ServiceController servicio;

    servicios =(ServiceController[])ServiceController.GetServices("127.0.0.1");

    for(i = 0; i <= servicios.Length - 1; i++)

    {

    if (serviciosIdea.ServiceName.CompareTo("Schedule") == 0)

    {

    servicio = (ServiceController)serviciosIdea;

    string status = servicio.Status.ToString();

    if (status.CompareTo("Running") == 0) servicio.Status = ServiceControllerStatus.Stopped;

    }

    }


  • hawaiian dude

    I think that this is more in line with what you are looking for as it provides a .NET wrapper for accessing the Win32 API’s responsible for working with Scheduled Tasks.

  • Scheduled Tasks in Windows