Windows – Batch: How to run a program when the computer is idle and stop when it’s used

batchwindows

I need to run a Windows batch (or any other command line software would do fine) that would run a program when the computer has been idle for a minute and stop it when it's used. I should obviously start it back again when it's idle again.

Any ideas? Couldn't find anything that doesn't use GUI.

Best Answer

This is a perfect job for AutoIt: http://autoitscript.com

Here's a script I threw together for you. Put it in an .au3 file, replace notepad with your exe, and for Run, include the full path:

#include <Timers.au3>
While 1
   Sleep(10)
   $idleTimer = _Timer_GetIdleTime()
   If $idleTimer > 60000 And Not ProcessExists("notepad.exe") Then
      Run("notepad.exe")
   ElseIf $idleTimer < 10 Then
      ProcessClose("notepad.exe")
   EndIf
WEnd
Related Question