Creating a scheduled task in Windows that will run at intervals indefinitely

74

Solution 1

I'd try it like this:

  1. Add a trigger: enter image description here Make sure to set the current date and 00:00:00 as the start time
  2. Make sure the task is run as soon as possible if the start was missed: enter image description here

Solution 2

Here's how to create such scheduled task using PowerShell:

$executable = "foo.exe"
$taskName = "My Task"
$action = New-ScheduledTaskAction -execute $executable
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable
Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -Setting $settings -description $description -User "NT AUTHORITY\SYSTEM" -RunLevel 1
$trigger.RepetitionInterval = (New-TimeSpan -Minutes 5)
$trigger.RepetitionDuration = (New-TimeSpan -Days 1000)
Set-ScheduledTask $taskName -Trigger $trigger
Share:
74

Related videos on Youtube

Bert Becker
Author by

Bert Becker

Updated on September 18, 2022

Comments

  • Bert Becker
    Bert Becker over 1 year

    I'm trying to use the scala-reflect package for android development. I have added the scala-reflect dependency in my build.sbt:

    libraryDependencies += "org.scala-lang" % "scala-reflect" % "2.11.8"
    

    but I get an exception:

    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/rmi/Remote;
                                    at scala.reflect.internal.Definitions$DefinitionsClass.RemoteInterfaceClass$lzycompute(Definitions.scala:370)
                                    at scala.reflect.internal.Definitions$DefinitionsClass.RemoteInterfaceClass(Definitions.scala:370)
                                    at scala.reflect.runtime.JavaUniverseForce$class.force(JavaUniverseForce.scala:255)
                                    at scala.reflect.runtime.JavaUniverse.force(JavaUniverse.scala:16)
                                    at scala.reflect.runtime.JavaUniverse.init(JavaUniverse.scala:147)
                                    at scala.reflect.runtime.JavaUniverse.<init>(JavaUniverse.scala:78)
                                    at scala.reflect.runtime.package$.universe$lzycompute(package.scala:17)
                                    at scala.reflect.runtime.package$.universe(package.scala:17)
    

    I have tried to add the java source of java.rmi.Remote and java.rmi.RemoteException and built the project with android:package --core-library (because sbt has not found the dexCoreLibrary option) , it builded successfully, but I got the runtime error.

    So, is it possible to add the java.rmi dependency otherwise, that scala.reflect can use it?

    I'm using the scala.reflect library in the context of an implementation of a method Option.orDefault:

    class RichOption[+A : TypeTag](val delegate: Option[A]) {
    
      def orDefault : A = delegate.getOrElse {
        delegate match {
          case t if typeOf[A] <:< typeOf[Int] => 0.asInstanceOf
          case _ => throw new IllegalAccessException("there is no default value for this type.")
        }
      }
    
    
    }
    

    If you know a better implementation for Option.orDefault (possibly without scala.reflect), please let me know.

  • Ross
    Ross about 12 years
    Thanks. "Run as soon as possible if the start was missed" was the key.
  • Michael
    Michael almost 10 years
    Hullo I think this only works if Duration is infinite - ([timespan]::MaxValue)