windows 7 - Reduce the Task Idle Conditions timeout from 15mins to 5mins

07
2014-07
  • laggingreflex

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa383561%28v=vs.85%29.aspx

    Detecting the Idle State

    In Windows 7, the Task Scheduler verifies that the computer is in an idle state every 15 minutes.

    Is there a way to lower that to, say, 5 minutes?

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    What windows 7 task scheduler event would respond to an idle END condition?
  • r_alex_hall

    The Windows 7 task scheduler allows me to run a task when the computer goes idle, but there doesn't seem to be any obvious way to run a task when the computer resumes from idle, or is no longer idle.

    Surely there's some event triggered in windows (an event log?) when the computer is no longer idle? Or some way to capture the fact that the computer is no longer idle, and respond to that with a scheduled task?

    How would I do this?

    Or, at worst, is there a command-line program somewhere that can invoke commands or events when the computer enters/exits idle status?

    [UPDATE:] The approach in my reply to Diogo Rocha works. I created a null executable via py2exe out of this script:

    import sys
    import time
    
    #restart a pause every twenty seconds, with two functions that call each other.
    
    def call_pause():
        pause()
    
    def pause():
        time.sleep(20)
        call_pause()
    
    call_pause()
    

    --and set up a scheduled task in Windows for which this is the exported HTML:

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2012-04-27T17:40:46.8871631</Date>
        <Author>GENIUS-BREATH-COMPY</Author>
        <Description>This task runs ProgA when the computer enters an idle state, and terminates ProgA when the computer *leaves* an idle state. The is all for scheduled TaskB, which periodically runs a batch that tests whether ProgA is running. If ProgA is not running (because this task terminated it), ProgB runs (as the computer is NOT idle). If ProgA *is* running, TaskB's batch does not run ProgB.</Description>
      </RegistrationInfo>
      <Triggers>
        <IdleTrigger>
          <Enabled>true</Enabled>
        </IdleTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>S-1-5-18</UserId>
          <RunLevel>HighestAvailable</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <Duration>PT1M</Duration>
          <WaitTimeout>PT0S</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>true</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>true</RunOnlyIfIdle>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT1M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\path_to\nullExecutable</Command>
        </Exec>
      </Actions>
    </Task>
    

    And left my computer idle for 15 minutes. Task manager showed the null executable running. As soon as I moved the mouse, it took the computer out of idle, and the null executable vanished from the task list.

    From here, it's a matter of setting up a task (or program--which I'm doing with Python and py2exe) that uses pslist (with an -accepteula switch so that on computers it's deployed to it will actually run the program) to check whether the null exe is running. If it is running, the %ERRORLEVEL% environment variable is set to 0 because pslist ran without error. If that environment variable is 1, it ran with an error (it didn't find the executable running). I'm exploiting that environment variable in a batch script to run another task if the computer is not idle.


  • Related Answers
  • Diogo

    I don't think it is possible to implement any methods to detect a trigger "border" on idle events(enter or exit from idle state), however there is a command that forcer your Windows to enter on idle state and run idle triggered tasks:

    Rundll32.exe advapi32.dll,ProcessIdleTasks
    

    You could combine another event(from event log) to run this command which in turn trigger another task that must be runned on idle state. As far you know you can freely combine any tasks that you may want.