SSzretter Posted April 25, 2014 Share Posted April 25, 2014 I have an autoit running as a windows service (as the SYSTEM user), and would like to detect whether the user is idle (no keyboard or mouse input). I found in a normal script I can use " _Timer_GetIdleTime". However, in my service / system user process the command does not work. Has anyone figured out a way to determine user activity/inactivity from a different process, not running as the user? Link to comment Share on other sites More sharing options...
JohnOne Posted April 25, 2014 Share Posted April 25, 2014 What exactly does not work about it? As far as I know only one use can be in control of mouse and keyboard at any one time, I'd not have thought it was user specific. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
KaFu Posted April 25, 2014 Share Posted April 25, 2014 How about using a slave background process running in user context? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
jguinch Posted April 25, 2014 Share Posted April 25, 2014 This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function. JohnOne 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
SSzretter Posted May 9, 2014 Author Share Posted May 9, 2014 What exactly does not work about it? As far as I know only one use can be in control of mouse and keyboard at any one time, I'd not have thought it was user specific. It always returns idle from a system service/process. Link to comment Share on other sites More sharing options...
SSzretter Posted May 9, 2014 Author Share Posted May 9, 2014 How about using a slave background process running in user context? That's exactly what I had to do, but I have found starting the process is not always reliable. I have had issues, for example when remote desktop is used, or fast user switching... It's working most of the time, but I also do not like the fact that it's an extra process running... I am just being picky and would love to have it all contained within one process. Link to comment Share on other sites More sharing options...
bobmcrae Posted January 31, 2016 Share Posted January 31, 2016 This thread is a bit dated, but I thought I'd add in case anyone needs to find out whether the system is idle. Essentially, you can check the IO Reads from the process csrss.exe, session 1. expandcollapse popupGlobal $lastIOReads, $currentIOReads Global $MINUTES = 1000*60 Global $sleepTime = Round(1*$MINUTES,0) pauseIfNotIdle() Func pauseIfNotIdle() if $lastIOReads='' Then ; checks to see if this is the first call of this function $lastIOReads = _getIOReads() ; sets initial value Sleep($sleepTime) ; sleep, to look for idle $currentIOReads = _getIOReads() ; wake & check whether there has been any user input Else $lastIOReads = $currentIOReads ; not the first call, set last IO reads = the most recent $currentIOReads = _getIOReads() ; set IO reads to current EndIf While $lastIOReads<>$currentIOReads ; if there has been a change in the IO reads, do the loop Sleep($sleepTime) $lastIOReads = $currentIOReads ; set last IO reads = the most recent $currentIOReads = _getIOReads() ; set IO reads to current WEnd EndFunc ; pauseIfNotIdle() Func _getIOReads() Local $objWMIService = ObjGet("winmgmts:\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_process where name="csrss.exe" and sessionId=1') ; csrss is the Windows input exe; session 1 is console, which is the active session If IsObj($colItems) then ; csrss will change its IO Reads with input to the keyboard or mouse For $objItem In $colItems Return $objItem.ReadOperationCount ; get IO reads Next Else Return False Endif EndFunc ; getIOReads() Geqsogen and orbs 1 1 Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2016 Share Posted January 31, 2016 Do IO reads not include disk activity? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
bobmcrae Posted February 2, 2016 Share Posted February 2, 2016 (edited) JohnOne, no: it appears the csrss / session 1 correlates ONLY to mouse & keyboard actions. Just startup task manager and watch that process IO Reads without touching the mouse or keyboard. While csrss may have other responsibilities, it seems to correlate almost entirely with keyboard and mouse activity. As an example, I logged into a remote PC I work with and took a snapshot of the IO Reads; 20-minutes later it's exactly the same value. Edit: After ~2-hours the IO Reads remain the same on the PC referenced above. Edited February 2, 2016 by bobmcrae orbs and JohnOne 2 Link to comment Share on other sites More sharing options...
JohnOne Posted February 2, 2016 Share Posted February 2, 2016 Good answer. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
orbs Posted February 2, 2016 Share Posted February 2, 2016 @bobmcrae, clever!!! but you are checking only session 1. what if you are on a multi-user environment? that's not uncommon for home pc's, i imagine terminal servers should apply the same consideration. you must first enumerate all active sessions, and then check them all - they must all remain unchanged for the system to be considered idle. or am i missing something? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
bobmcrae Posted February 3, 2016 Share Posted February 3, 2016 orbs: You're right; in a multi-user environment to test for idle one would need to enumerate among the non-zero sessions. However, in my case, I am interested in the user session that started my script; hence the need to just check session 1. iLLiCiTgr 1 Link to comment Share on other sites More sharing options...
iLLiCiTgr Posted May 23, 2017 Share Posted May 23, 2017 wow! Amazingly enough, this discussion saved me a lot of time and energy searching the web. It seems the Windows10 Creators Update broke something in the behavior of GetLastInputInfo . And even though this post has nothing to do with autoit (sorry mods), i just wanted to say a big thank you @bobmcrae for providing a strange, but perfectly working solution still working on Windows10 Creators Update. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now