Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ VBscript ➜ Idle time.

Idle time.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Ochbad   (2 posts)  Bio
Date Fri 25 Feb 2005 05:05 AM (UTC)
Message
Is it possible somehow (with VBscript) to determine the idle time of the computer?

I would like to make a script that does something when the computer is idle, and something else when the user comes back.
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #1 on Sat 26 Feb 2005 08:51 AM (UTC)
Message
You can use WMI for that. I am not exactly sure that the values of the following property can be interpreted as indicator of "idleness" - it just shows the average amount of time the processor spent outside the idle thread lately:


set proc = GetObject("winmgmts:").InstancesOf ("Win32_PerfFormattedData_PerfOS_Processor")
  for each p in proc
    WScript.Echo p.PercentProcessorTime
  next


I am also unsure of what the individual members of that collection are: I have 2 logical processors and the collection for my system consists of 3 elements, so one of those elements either represents an average on two processors or the value for the physical processor, or something else. Perhaps, a simple average of all elements will do:


function IsIdle()
  dim total, count, procs, average
  set procs = GetObject("winmgmts:").InstancesOf("Win32_PerfFormattedData_PerfOS_Processor")
  total = 0
  count = 0
  for each proc in procs
    total = total + proc.PercentProcessorTime
    count = count + 1
  next
  average = total/count
  if average < 5 then
    IsIdle = vbTrue
  else
    IsIdle = vbFalse
  end if
end function
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #2 on Sat 26 Feb 2005 01:17 PM (UTC)
Message
I think it would be easier for you to get the cursor position every 3 minutes or so and see if it has changed. If it has, the user probably is at the PC...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Ochbad   (2 posts)  Bio
Date Reply #3 on Sat 26 Feb 2005 11:37 PM (UTC)
Message
I was so busy looking for a prepackaged solution I didn't even think of that simple cursor method. Should work!

Thanks!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,165 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.