4

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.

6

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
1
  • Hey Xichael, thanks a lot! This solves my problem. Now, if you could help me understand how I can refference to a folder behind %appdata%, I would be most grateful. Let's say I wanted to refference a file at %appdata%\Microsoft\file.txt, for example. How would you do that? I saw I need to refference it like this: @AppDataCommonDir But I don't know the syntax Autoit expects from me. – user2723297 Jan 12 '14 at 20:26
7

If you don't want to use AutoIt then look into the quser command which displays, amongst other things, the idle time to the nearest minute:

C:\Users\Richard>quser
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
>richard               console             1  Active      none   26/06/2014 15:29
C:\Users\Richard>

One simple way would be to test the output of:

quser | findstr /I %USERNAME% | findstr "none"

and if it comes back empty, then they are over 1 minute idle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.