How to get the idle time in Windows XP using VBA?

空扰寡人 提交于 2019-12-11 06:04:14

问题


I would like to know the current idle time from user input on a given Windows XP machine programmatically. I am using VBA in MS Access. What options do I have?


回答1:


I used the following to obtain the solution.

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long

Private Type LastInputInformation

    cbSize As Long

    dwTime As Long

End Type

Public Function GetUsersIdleTime() As Long

    Dim lii As LastInputInformation

    lii.cbSize = Len(lii)

    Call GetLastInputInfo(lii)

    GetUsersIdleTime = FormatNumber((GetTickCount() - lii.dwTime) / 1000, 2)

End Function

There are other parts of the system which can be idle such as,

  • CPU
  • Disk
  • Network
  • Other devices

To find out more regarding performance and other idle types see this SO post here.



来源:https://stackoverflow.com/questions/2589236/how-to-get-the-idle-time-in-windows-xp-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!