Peterpan8383

Close Idle Application

9 posts in this topic

I'm setting up a kiosk computer for accessing a payroll site.  For privacy and security reasons, we would like to close the session after idling for some time.

I happened to find this script and modified it for my own use.  It does the following:

  • Check for an application windows with the tile starting with "PayDay"
  • It does not limit to a certain application.  So any browser opening the targeted site will be monitored.
  • Start counter when the window in not in focus
  • Close the window when time limit is reached

There is one problem, however.  If the previous user leaves while having the browser window in focus, the script will not count it as idle time.  I wonder if there is a way that we can overcome this.

Hope some experts there may have some insights for me.

 

Pete

 

; ================================================ 

Opt("WinTitleMatchMode", 1) ;1 = Start of String
Opt("TrayIconDebug", 1)

$S_running = "check-4-app" ;name the script
If WinExists($S_running) Then Exit
AutoItWinSetTitle($S_running)

$title = "PayDay"   ; "PayDay is the title of the site"
$count = 0
While 1
    $state = WinGetState($title)
    $count += 1

    If $state = 15 Or $state = 47 Or $state = 0 Then $count = 0

    If $count > 10 Then WinClose($title)  ;close after idling for 10 seconds

    ToolTip("count = " & $count, 0, 0, "state = " & $state)
    Sleep(1000)    ; reloop in 1 sec
WEnd

; ================================================ 

 

 

Share this post


Link to post
Share on other sites



Well, until the experts get here... my first thought was if you ran a screensaver to look for that .scr process and then kill your windows, but I did a quick search and ran across this old thread that might better suit your needs - especially jmon's and stormbreaker's posts.

 

Share this post


Link to post
Share on other sites

Have a look at _WinAPI_GetIdleTime in the Help File.  This will give the time in milliseconds since the last user input.  

 

Adam

 

Share this post


Link to post
Share on other sites

I once wrote a similar script. Will post after my vacation (27th Oct)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This seems to work well - if there is no keyboard or mouse input, it kills the window if it exists.

#include <WinAPISys.au3>
$title = "PayDay"   ; "PayDay is the title of the site"
$minutes = 15

While 1

    ;if the timer is more than X minutes then:
    If _WinAPI_GetIdleTime() >= $minutes * 60 * 1000 AND WinExists($title) Then
        MsgBox (0, "Time reached", "You have been idle for more than " & $minutes & " minutes.", 5)
        WinClose($title)
        ; Exit
    EndIf

    ;Sleep for 5 seconds before looping again:
    Sleep(5000)
WEnd

 

Edited by MuffinMan

Share this post


Link to post
Share on other sites

Yeah, the MsgBox was in the original code and I left it in just for testing / debugging purposes.  If the OP truly wants a popup, then the Msgbox needs to have a timeout on it.  I edited my earlier post to include a 5 second timeout on the MsgBox.  Thanks for keeping me straight, Bill! ;-)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

PeterPan8383,

has your problem been solved with the examples you got or do you want me to post my script too?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now