1

Following an advice given to me in this question I have made this question. So I have an exe I want to run after the computer is idle (by idle I don’t mean sleep, I mean inactive or not being used) for sometime lets say 30 mins. Once the “inactive” timeout reaches I want the application to run. Saying that my PC is set up to only have the option “Screen sleep after “ in the Power options no Computer sleep, so the PC doesn’t go to sleep or the screen gets lock-screen unless I forced it using Windows+L keys, and I want to keep these settings as it is. I want to detect an inactivity time period and once the inactivity time period is reached then I want to execute an exe. Any idea how this can be done?

EDIT:

I've followed the steps provided in the answers:

Created a new task, added a trigger, set it to event: on Idle and created the task. In the conditionstab, specified the task waits 1min to become idle (instead of 10min just to test).

But then I wait for more than 10mins and the task is never triggered on PC1 but triggers on another PC2. I've checked online and found that PowerCfg -requests will show what is stopping the PC from being Idle and when I run it on PC2 nothing returns but when I run it on PC1 I get this "Legacy Kernel Caller" driver.

So I used Powercfg -requestsoverride but when I run powercfg -requestsoverride Driver "Legacy Kernel Caller" System , where it succeeds and I find it in the Powercfg -requestsoverride list, but then powercfg -requests it still shows [DRIVER] Legacy Kernel Caller under SYSTEM: and the task is never triggered any advice please?

  • So you want the application to prevent your system from locking? This isn’t a corporate machine is it? – Ramhound Jul 14 at 6:15
  • @Ramhound No, the machine never locks unless I force locking it using windows+L keys. I want to detect an inactivity time period then when it reaches this inactivity time limit I run the exe. Is it clearer now? – Tak Jul 14 at 6:17
  • Are you familiar with any programming language? It is easy if yes. – Bhavya Gupta Jul 14 at 6:26
  • @BhavyaGupta Yes, C# – Tak Jul 14 at 6:29
3

What you want is easy. You can do it using task scheduler.

When creating a task, under Conditionstab, you have the option to start the task if computer is idle for: . In there just put how much idle time you want.

enter image description here

Just program the .exe you want to run, how often you want it and then use the idle condition.

| improve this answer | |
  • Much better, easier and convenient than my answer. +1 :) – Bhavya Gupta Jul 14 at 6:35
  • So this “Idle time” doesn’t mean computer being sleep? – Tak Jul 14 at 6:37
  • No, it means no keyboard activity/mouse movement. – Overmind Jul 14 at 6:37
  • @Overmind Okay, will try it out. – Tak Jul 14 at 6:38
  • @Overmind I am thinking now, if the idle time reached and the exe started and then nothing happened for the same time idle time, this will relaunch the exe and will be running twice, any idea how to avoid that? – Tak Jul 14 at 7:23
1

The far easiest solution is to use good old Task Scheduler.

Task Scheduler does not just allow you to set tasks on certain times dates, but it can actually also set tasks on certain events, such as at logon, and yes, also when idle.

Create a new task, add a trigger, set it to event: on Idle and create the task. In the conditionstab, you can specify how long the task waits to become idle (you set this to 30 minutes).

In addition, you can also automatically kill the task when the system becomes active again all from Task Scheduler.

| improve this answer | |
  • So this Idle time doesn’t mean computer being sleep? As mine never goes to sleep. – Tak Jul 14 at 6:37
  • No, it means, no mouse movement nor key presses. – LPChip Jul 14 at 6:41
  • I am thinking now, if the idle time reached and the exe started and then nothing happened for the same time idle time, this will relaunch the exe and will be running twice, any idea how to avoid that? – Tak Jul 14 at 7:21
  • It will not. It goes into idle state and the task fires, and it will not fire it again until the computer goes out of idle state at least once, unless the app itself somehow makes the computer think its no longer idle. But setting up the task allows you to not check for idle time for a certain amount of time anyway. So Wait until the computer becomes idle for 30 minutes, and don't check idle time for 4 hours will basically say: once it reaches idle for 30 minutes, it will not check again until 4 hours have elapsed. – LPChip Jul 14 at 8:22
  • could you explain with a screenshot in your answer how this can be done? Like this is my case in detail, I have an exe which opens a form for the computer user to fill, so if the idle time reached the form will open, now if a user after that moved the mouse or keyboard he will see this form and fill it and it will close, so if the computer becomes idle for x time again the form will open again and so on. – Tak Jul 14 at 8:37
0

Sorry not in c# but is easy enough. 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

Reference - https://superuser.com/a/700647/1092861

| improve this answer | |
  • This will not work in my case as it relies on the idletime which means a computer being sleep, my computer never gets into an idle state and go to sleep, only the screen goes to sleep. – Tak Jul 14 at 6:31
  • @Tak you are taking wrong definition for idle time. The computer goes to sleep after say 5 minutes of idle time. It means when no key is pressed or mouse moved. – Bhavya Gupta Jul 14 at 6:33
0

You can use schtasks from command prompt to make the task easier:

schtasks /create /tn "My Task" /tr "EXE Application path" /sc onidle /i Number_Of_Minutes_Inactive
| improve this answer | |

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.