[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Idle time.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Idle time.

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


Posted by Ochbad   (2 posts)  [Biography] 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.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] top

Posted by Ochbad   (2 posts)  [Biography] 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!
[Go to top] 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.


10,776 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]