Page 1 of 1 1
Topic Options
#119844 - 2004-05-19 07:07 PM Detect user idle or inactivity
@lejo @rias Offline
Starting to like KiXtart

Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
Hi, whit kixtart How to Detect User Idle Time or Inactivity, and save in a variable that time...

pls

PD: I will run that script every 10 min with a sheduler task and If the user have a 10 mins in inactivity then run other task...
_________________________
Look always 4 the best...

Top
#119845 - 2004-05-19 07:12 PM Re: Detect user idle or inactivity
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You can have Scheduled Tasks on run if the computer is idle. Check the advanced properties for the scheduled task for these settings.
Top
#119846 - 2004-05-19 07:14 PM Re: Detect user idle or inactivity
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you can also detect if the screensaver is active (look for the processname)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#119847 - 2004-05-20 11:13 AM Re: Detect user idle or inactivity
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
A very simple way to tell how idle your system is is to see how much time the system idle process is clocking up.

The script below checks how idle the system has been between each interval.

Code:
Break ON

$=SetOption("Break","ON")

$iIntervalCheck=30 ; Check every thirty seconds.

$iThresholdValue=0,5,30,50,80,95
$sThresholdText="I have no time right now!", "Busy", "In use", "A little idle", "Idle", "Very Idle"
$sThresholdColour="r+", "r", "y", "y+", "g", "g+"

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
If @ERROR @ERROR ": " @SERROR ? EndIf

; Get initial status
$iLastTime=Int(@TICKS/1000)
$iLastIdle=GetIdleSeconds()

$iNumCPU=GetCPUCount()

@TIME+" Waiting for first "+$iIntervalCheck+" second interval to expire, CPU count is "+$iNumCPU ?
While Not KBHit()
Sleep $iIntervalCheck
$iThisIdle=GetIdleSeconds()
$iThisTime=Int(@TICKS/1000)
$iDeltaIdle=$iThisIdle-$iLastIdle
$iDeltaTime=$iThisTime-$iLastTime
$iPercentIdle=CInt(($iDeltaIdle*100/$iDeltaTime)/$iNumCPU)
For $i=0 to 5
If $iPercentIdle>=$iThresholdValue[$i] $iIndex=$i EndIf
Next

Color $sThresholdColour[$iIndex]/n
Chr(13)+" "+CHR(13)
@TIME+" Idle: "+$iPercentIdle+"% "+$sThresholdText[$iIndex]

$iLastIdle=$iThisIdle
$iLastTime=$iThisTime
Loop

Get $
Exit 0

Function GetIdleSeconds()
$GetIdleSeconds=0
$colItems = $objWMIService.ExecQuery('Select KernelModeTime from Win32_Process where Handle="0"',,48)
For Each $objProcess in $colItems
$GetIdleSeconds=$objProcess.KernelModeTime
; Time is in nanoseconds - Too much!
$GetIdleSeconds=CInt(SubStr($GetIdleSeconds,1,Len($GetIdleSeconds)-7))
Exit 0
Next
Exit 1
EndFunction

Function GetCPUCount()
$GetCPUCount=1
$colItems = $objWMIService.ExecQuery('Select NumberOfProcessors from Win32_ComputerSystem',,48)
For Each $objComputer in $colItems
$GetCPUCount=$objComputer.NumberOfProcessors
Exit 0
Next
Exit 1
EndFunction


Top
#119848 - 2004-05-20 11:16 AM Re: Detect user idle or inactivity
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Nice Richard,

Question... does the running of this script affect the idleness ?

Top
#119849 - 2004-05-20 11:36 AM Re: Detect user idle or inactivity
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Question... does the running of this script affect the idleness ?




Yes of course to a small degree.

It is very low for reasonable intervals, and even when I had the interval as low as 3 seconds during testing the idle time was never below 100% when nothing else was running. For longer periods it will have less impact.

To test it, set the interval period to a 1 second, start task manager to monitor what it thinks CPU usage is and then start a process - I used "dir /s" in the root directory.

You will see that the values of idle time from the script and CPU time in task manager are pretty close.

If the script is going to be called by a scheduled task then the "last" values need to be stored in and recalled from the registry or a file, and a sanity check needs to be made to reset the values if the process is not run for some time, the machine is restarted or the counters wrap.

Top
#119850 - 2004-05-20 04:31 PM Re: Detect user idle or inactivity
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
This might not be of any help to you right now... but i think shawn is going to expose This API in kixforms.... hopefuly soon See this thread on Kixforms BBS

Bryce


Edited by Bryce (2004-05-20 04:32 PM)

Top
#119851 - 2004-05-20 04:45 PM Re: Detect user idle or inactivity
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
last time I asked for it (about half'n year ago) he wasn't so keen about it.
so don't expect it soon.
_________________________
!

download KiXnet

Top
#119852 - 2004-05-20 05:36 PM Re: Detect user idle or inactivity
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
it is in the documentation for the latest KF build.... just cant seem to get it to work.
Top
#119853 - 2004-05-20 05:47 PM Re: Detect user idle or inactivity
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
ahh Shawn just made a post on the kixforms board, this feature is a "work in progress"
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.066 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org