![]() |
|
29 May 2013 | #1 |
|
Run task on unlock after certain period of time
My computer is set to automatically lock after 10 minutes of user idle. I want to run a task when I log on, but only if the machine has previously been idle for an hour. This is so the task only runs when I've actually been away from the computer, not just if it's timed out. Is this possible?
|
My System Specs![]() |
. |
|
30 May 2013 | #2 |
|
1. Have you tried task scheduler - create task -... triggers - new -begin .. - on WS unlock
Then once it is setup disable it. But you would have to enable it if you knew how long the machine would be unattended. I did not see any option for the task to run only if idle for 1 hour though. 2. Or you could not use task scheduler - just set up a .bat file and run it manually as needed. Welcome to the best Windows Forum on the Web! I have a question, has anyone ever stumped the "panel" here at seven forums? I wish I had joined here long ago! |
My System Specs![]() |
30 May 2013 | #3 |
|
Like Josea mentioned, welcome to the Seven Forums and you can use a scheduled task to run the app of interest when you unlock the computer. The only way that I can think of to accomplish the idle time condition is to use a scripting tool like AutoIt3. You will need to write your own script. You can search (join?) the AutoIt forums for help or I might be able to help a bit in these forums.
Have your script start when you boot the computer. The script tracks idle time. If that idle time exceeds 60 minutes, then have the script create a simple text file. Then - have the scheduled task run a batch file upon WS unlock. Have the batch file run your app only if the file exists. Code:
IF EXIST c:\myfolder\idle.txt myapp.exe Or - depending on what the app does that you want to run - you can let the script start it after the 60 minutes of idle time and even if the computer is locked. |
My System Specs![]() |
. |
|
30 May 2013 | #4 |
|
@Josea,
By the way, I left my browser open to this thread for for many hours while attempting to come up with a solution. It was not until you posted about the scheduled task trigger of workstation unlock that the pieces for what I was wanting to post came together. I don't use scheduled tasks much and I had no idea that unlocking the computer could be the trigger. There probably is a pure AutoIt solution, but off of the top of my head, I don't know how to reliably have AutoIt detect when the workstation has been unlocked. I hope that the OP can make use of our combined efforts. |
My System Specs![]() |
30 May 2013 | #5 |
|
That's a crazily impressive solution, thanks both of you for your input! It's a little more complicated than I was hoping (as I want to put it on a few computers if successful), but nothing I can't work with.
So far I've got an AutoIt script which is creating the idle file (on demand), an AutoIt script which is running the batch file hidden (successful), and the batch file running the program and deleting the idle file (successful). I then ran out of time so will get back to it later today. What I still need to do is improve the idle file script so that it runs on startup and then checks for idle every 10 minutes (currently only checks once when I run it). I'll then setup the task which runs the hidden batch file script to run every 10 minutes as well. Between the two of them it should be able to do what I'm trying to do. I'll post again once I've had another go at it. |
My System Specs![]() |
30 May 2013 | #6 |
|
It sounds like your requirements have changed a bit... and that is fine.
Below is one way to do what you originally asked about doing: Code:
AutoItSetOption ("TrayIconDebug", 1) ;prevents multiple copies of the script from running $S_running = "idle-timer-test" ;name the script If WinExists($S_running) Then Exit AutoItWinSetTitle($S_running) ;you can remark this out too - you always want the script to run HotKeySet("+{ESC}", "_end_this") ; press Ctrl-ESC to end script #include <Timers.au3> #include <File.au3> ;delete the file if it happens to be there FileDelete(@MyDocumentsDir & "\idle-time.txt") While 1 Local $iIdleTime = _Timer_GetIdleTime() ;the tray tip is just for debugging - it can be remarked out TrayTip('press Shift+ESC to end script', "been idle for about " & $iIdleTime & "ms", 100) Sleep(1000) If $iIdleTime > (1000 * 60) Then ;add another times 60 to make it one hour _FileCreate(@MyDocumentsDir & "\idle-time.txt") Do ;the tray tip is just for debugging - it can be remarked out TrayTip('press Shift+ESC to end script', "waiting for idle-time.txt to be deleted", 100) Sleep(1000) Until Not FileExists(@MyDocumentsDir & "\idle-time.txt") EndIf WEnd Func _end_this() Exit EndFunc Code:
if exist "C:\Users\username\Documents\idle-time.txt" notepad.exe del "C:\Users\username\Documents\idle-time.txt" pause Maybe you can glean something from the code above. Below the second video in this post is some info about AutoIt that you might want to keep in mind. |
My System Specs![]() |
31 May 2013 | #7 |
|
It sounds like your requirements have changed a bit... and that is fine.
Below is one way to do what you originally asked about doing: Code:
AutoItSetOption ("TrayIconDebug", 1) ;prevents multiple copies of the script from running $S_running = "idle-timer-test" ;name the script If WinExists($S_running) Then Exit AutoItWinSetTitle($S_running) ;you can remark this out too - you always want the script to run HotKeySet("+{ESC}", "_end_this") ; press Ctrl-ESC to end script #include <Timers.au3> #include <File.au3> ;delete the file if it happens to be there FileDelete(@MyDocumentsDir & "\idle-time.txt") While 1 Local $iIdleTime = _Timer_GetIdleTime() ;the tray tip is just for debugging - it can be remarked out TrayTip('press Shift+ESC to end script', "been idle for about " & $iIdleTime & "ms", 100) Sleep(1000) If $iIdleTime > (1000 * 60) Then ;add another times 60 to make it one hour _FileCreate(@MyDocumentsDir & "\idle-time.txt") Do ;the tray tip is just for debugging - it can be remarked out TrayTip('press Shift+ESC to end script', "waiting for idle-time.txt to be deleted", 100) Sleep(1000) Until Not FileExists(@MyDocumentsDir & "\idle-time.txt") EndIf WEnd Func _end_this() Exit EndFunc Code:
if exist "C:\Users\username\Documents\idle-time.txt" notepad.exe del "C:\Users\username\Documents\idle-time.txt" pause Maybe you can glean something from the code above. Below the second video in this post is some info about AutoIt that you might want to keep in mind. In conclusion: On startup the idle-timer-test script (see above) runs. This virtually constantly calls the idle time from Windows. When this exceeds one hour the script creates a file in My Documents and then waits until that file is deleted before getting the idle time again. When I unlock, the batch file checks to see if the idle time file exists. If so the batch file runs the program and then deletes the file so that the idle script starts getting the idle time again. If the file doesn't exist then the batch files does nothing. The only other thing I did was wrap the batch file in an AutoIt script Code:
Run("check-run-notepad.bat", "", @SW_HIDE) Thanks for your efforts with this, much appreciated! |
My System Specs![]() |
31 May 2013 | #8 |
|
You are welcome.
I was just curious about how such a script would look so I put that code together. Calling the batch file via a second AutoIt script so that the cmd window is hidden is fine, but you might want to explore having that second AutoIt script replace the batch file: Code:
If FileExists(@MyDocumentsDir & "\idle-time.txt") Then Run("your app here") EndIf Code:
If FileExists(@MyDocumentsDir & "\idle-time.txt") Then Run("your app here") |
My System Specs![]() |
![]() |
Thread Tools | |
Similar help and support threads | ||||
Thread | Forum | |||
Monitor turn off after long period time Why does my screen sometimes goes blank after a period of inactivity ( like 8 hours )? And sometimes not!. My monitor screen just turns off ( yellow light ). Then i just turn my mouse and screen goes back to normal. ITS TOTALLY RANDOM! I have disabled all sleep functions. I disabled the... |
Graphic Cards | |||
task bar wont unlock and cant pin icons so after recovering from a blue screen can unlock task bar or pin icons to it made vid to show just whats its doing https://www.youtube.com/watch?v=pPmqc4K5-eE |
General Discussion | |||
Several BSODs within short period of time Hello. I encountered several BSODs within days of each other. I don't play games or download anything on my PC. I just use it for surfing the net and general usage (mostly Office). I also technically faced a blue screen just 2 days ago. I clicked on a folder and suddenly my monitor flickered and... |
BSOD Help and Support | |||
Multiple BSoD over a period of time. Hello, I have been getting these BSoD's for a while now, and I have tried to figure them out, but I can't seem to. It's normally a "DRIVER_IRQL_NOT_LESS_OR_EQUAL" or something along those lines. It generally happens when I try to play any intensive games. I have tried updating my drivers, or at... |
BSOD Help and Support | |||
PC slow's down a lot after a period of time I have a very idiotic problem in which i start the PC, play for 20 minutes and then the computer starts to load it self for no reason. The CPU usage is close to 98% so i can't play no more. Same thing if i restart the PC, it works like a charm for 20 minutes then it slow's down. :mad: Any ideas? |
Performance & Maintenance |
Our Sites |
Site Links |
About Us |
Find Us |
Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd All times are GMT -5. The time now is 16:14. |
![]() ![]() ![]() ![]() ![]() |